Welcome Guest, Not a member yet? Register   Sign In
Undefined model
#1

[eluser]Martenvanurk[/eluser]
Dear,

I'm using the following code:

Code:
$this -> load -> model ( 'AclModel' );

$this -> load -> model ('MenuModel');
$this -> MenuModel -> setAcl ( $this -> AclModel );

This is my model:
Code:
class MenuModel extends CI_Model {
    /**
     * Acces control list object
     * @var object
     */
    private $acl;

    public function setAcl( &$acl )
    {
        $this->acl = $acl;
    }
}

When I create an error in the model, CI report it fine. So the model is loaded normal.
But when I use the code in the first block in my controller I got the following error:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Menu::$MenuModel

Filename: controllers/Menu.php

Line Number: 36

Line 36 is this line ( first code block): $this -> MenuModel -> setAcl ( $this -> AclModel );

In the code before this, I loaded the MenuModel without any problems. Will this cause the error? Think CI will use the Singleton or Dependency Injection container though.

How can I fix this error, the syntax is right I think.....

Kind regards!
Marten
#2

[eluser]gRoberts[/eluser]
It's likely the model isn't actually getting loaded correctly.

As a test, try

Code:
$AclModel = $this->model->load('AclModel')
$MenuModel = $this->model->load('MenuModel');
$MenuModel->setAcl($AclModel);
#3

[eluser]Martenvanurk[/eluser]
mmmm. working now..... How can you explain this?
#4

[eluser]gRoberts[/eluser]
This confirms my initial suspicions.

Code:
$this->model->load('model_model');
will set $this->model_model and also return an instance of the model when you call it.

If neither are being set, it appears your model is not loading. Do you have other models that work? It may be related to your naming convention. I think it should be "Acl_model" and "Menu_model" although I have never tried it any other way, so it may work.

Within both of your defined models, are you calling
Code:
parent::__construct();
in your constructor? It could be that your not initialising the underlying model class and it's refusing to load correctly?
#5

[eluser]Martenvanurk[/eluser]
About the naming convention, there are more models which are working well. Even the same menu module is loaded earlier and works well.

I always loads the contructor....
#6

[eluser]gRoberts[/eluser]
Sorry to sound like I was questioning your ability, I just had to ask just in case.

Code:
var_dump($this->MenuModel);

What does the above produce?
#7

[eluser]Martenvanurk[/eluser]
null it is Smile




Theme © iAndrew 2016 - Forum software by © MyBB