Welcome Guest, Not a member yet? Register   Sign In
call to member function on non-object
#1

[eluser]MydKnight[/eluser]
This time I actually found other people with the same kinds of issues...but I'm just not up to speed enough to get the solution. Here is what I am seeing when I try to add a new user:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$M_user

Filename: controllers/welcome.php

Line Number: 66


Fatal error: Call to a member function createUser() on a non-object in /home/abadmin1/public_html/rework/system/application/controllers/welcome.php on line 66

here is the controller:

function usr_register()
{
if ($this->input->post('username')){
$this->M_user->createUser();
$this->session->set_flashdata('message','User added');
redirect('index','refresh');
}else{
$data['title'] = "ABC User Registration";
$data['navlist'] = array(
'home' => 'Home'
);
$data['main'] = 'users/user_create';
$this->load->vars($data);
$this->load->view('abctemplate');
}
}

And here is an (abbreviated) function from the model:

function createUser(){
$this->username = $this->input->post('username');
$this->user_password = $this->input->post('user_password');
$this->user_email = $this->input->post('user_email');
.
.
.
$this->user_contype = $this->input->post('user_contype');

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

What am I doing wrong this time?
#2

[eluser]Dam1an[/eluser]
I'm going to assume the model us called M_user? (I have to make that assumption as I don;t see the part where you load it

It should be lower case when you call it, so m_user instead of M_user
#3

[eluser]MydKnight[/eluser]
the constructor is class M_user , function M_user. The model itself is m_user.php. The load is loaded as m_user in the config file. I think this is right, but I have to say, the casing necessary to get models to work right is really messin with my head. I can't even seem to find agreement within the forums...some say all lower case, some have a mixture of both. Let me know if how I have this one set up is wrong...but I am pretty sure I have it correct.
#4

[eluser]VirtualDevel[/eluser]
Can u post the __construct() or is m_user autoloaded?
#5

[eluser]MydKnight[/eluser]
I am auto loading m_user from the config file.
#6

[eluser]MydKnight[/eluser]
You had asked about the original constructor. I assume this is what you are referring to:

class M_user extends Model{
function M_user(){
parent::Model();
}

Does that help?
#7

[eluser]Dam1an[/eluser]
Did you try changing the case as I suggested when you actually used it (Maybe I wasn;t clear what I was refering to)

Code:
// Change this
$this->M_user->createUser();
// to this
$this->m_user->createUser();

This is because although PHP is case insensitive on the whole, I'm pretty sure user defined variables are case sensitive, and CI will create the variable in lower case




Theme © iAndrew 2016 - Forum software by © MyBB