-2

I have the following code in model:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Membership_model extends CI_Model 
{

    function __construct()
    {
        parent::__construct();
    }

    public function register_user($info)
    {
        if(isset($info))
        {
            $data = array(
               'fullname' => $info['fullname'] ,
               'mobile' =>  $info['mobile'] ,
               'telephone' =>  $info['home'] ,
               'username' =>  $info['username'] ,
               'password' =>  $info['password'] ,
               'email' =>  $info['email'] ,
               'member_type' =>  $info['memberType'] 
            );

            $this->db->insert('users', $data);
        }
    }

}

and am calling it this way in controller:

$info = array('fullname' => $fullname , 'mobile' => $mobile, 'home' => $home,
              'username' => $username, 'password' => $password,        
              'memberType' => $memberType, 'email' => $email );

$this->membershipModel->register_user($info);

Nevertheless, I am getting this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Membership::$db

Filename: core/Model.php

Line Number: 51

Any idea what that means? regards,

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
sys_debug
  • 3,883
  • 17
  • 67
  • 98

1 Answers1

1

In CodeIgniter, class and method names are case sensitive:

$this->membershipModel->register_user($info);  

should read...

$this->Membership_model->register_user($info);

NOTE
Make sure you name your model file as: membership_model.php as specified in the CodeIgniter documentation.

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
  • actually the whole issue it didn't recognize the word db. I loaded the database library and done. – sys_debug Mar 12 '13 at 21:00
  • Of course, you do need to load the right classes. Do you have another model called `membershipModel` ? – Marc Audet Mar 12 '13 at 21:04
  • Where did you read that class/method names are case sensitive in PHP? See [this](http://stackoverflow.com/questions/2749781/why-are-functions-and-methods-in-php-case-insensitive) for a reason as to why they are case *insensitive* – kittycat Mar 12 '13 at 21:05
  • Good question, here is my reference: http://ellislab.com/codeigniter/user-guide/general/models.html The documentation does not state that naming is case sensitive. However, the wording lead me to believe that it was, namely, class names must begin by upper case and file name must be lower case. However, this could simply be CodeIgniter's convention and not necessarily PHP. I appreciate your point. – Marc Audet Mar 12 '13 at 21:09
  • 1
    @MarcAudet that is **CI** being case sensitive when handling the loading and calling of the classes as the filesnames for the class is case sensitive. Update your post so you don't incorrectly say that it is PHP being so. – kittycat Mar 12 '13 at 21:12
  • 1
    @crytic I made the changes based on your comments, thank you! – Marc Audet Mar 12 '13 at 21:14