• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading a model inside a model


I would like to have a model, that loads in various different models.

For example if you had a car model, it would load in the engine model, wheel model, interior model etc etc

The problem I have is codeigniter doesn't seem to allow me to load a model inside a model.

So when inside my car model, if I do the following:

$this->load->model('Engine_model', '', TRUE);
$this->engine = $this->Engine_model->load_from_id( $this->engineIdFk );

I get this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Car_model::$Engine_model

Filename: models/car_model.php

Line Number: 123

Is there a different way to load a model, or should my Car_model not really be a model, or at lease extend the codeigniter Model class?



[eluser]Mike Ryan[/eluser]
Hi Rob,

You need to call the engine model via the CI instance:

$CI =& get_instance();
$this->engine = $CI->Engine_model->load_from_id( $this->engineIdFk );

Thanks Mike!

I had just found this:


Someone there posted the same solution, seems to work Smile



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.