Welcome Guest, Not a member yet? Register   Sign In
loading models within models not allowed in CI 2.0.2? Go back to 1.7.2?
#1

[eluser]Xerix[/eluser]
Hello All, I have a peculiar problem.

I get 'Fatal error: Call to a member function model() on a non-object in C:\Programming\www_root\passport\models\pages_model.php on line 15'

My directory structure for my 2 projects is
+www_root
----+passport (my app that doesnt work!)
----+cmt (my app that does work!)
----+system (Codeigniter 2.0.2)

code that generates error
Code:
class Pages_model extends CI_Model{
        
    function __construct(){
        parent::__construct();
        
        $this->load->model('Menus_model'); //LINE 15
    }

I thought you fixed this problem from CI 1.7.2?

Any Ideas? I upgraded to get around the problem of loading Models within Models. Is there something I need to change in my config somewhere. Also I am extending and constructing my classes properly using CI_Controller, CI_Model and using parent::__construct within the __construct function.

I have been pulling my hair out for 2 days now. Any help is much appreciated before I abandon CI 2.

Thanks
#2

[eluser]danmontgomery[/eluser]
Was this ever allowed? You can load the menus_model before you load pages_model, in which case it's accessible like anything else, or:

Code:
$ci = get_instance();
$ci->load->model('menus_model');
#3

[eluser]Xerix[/eluser]
Sorry, I should have been more specific. No it was not allowed in 1.7.2. And I used the above method. However, I am trying to use the new way as I have my new cmt project I am making and would like to use it. Any Ideas?
#4

[eluser]danmontgomery[/eluser]
2 ideas... The ones I suggested Tongue
#5

[eluser]Xerix[/eluser]
LOL, I was afraid you might say something like that. No worries, not a big deal. Out of curiosity, does CI2+ support calling $this->load->model within another model?

Thanks
#6

[eluser]danmontgomery[/eluser]
Huh. I could have sworn you couldn't, but I just tested in Reactor and you can. The error you're seeing is that load isn't an object. I would assume you can't load anything?
#7

[eluser]Xerix[/eluser]
I just checked and load is in fact null.

Shouldn't the base model class CI_Model handle the creation of load? as in $this->load is not null?

Andrew




Theme © iAndrew 2016 - Forum software by © MyBB