Welcome Guest, Not a member yet? Register   Sign In
Loading a model within a model.
#9

[eluser]gtech[/eluser]
Quote:
Quote: Ok I get you, I only load my models within the model constructor and thats why it works in my case, if I moved the load outside the constructor it probably wont work.. Thanks for the info.
No, I believe it works in your case because those models were already previously loaded in your CI instance (somewhere in your controller), before the construction of the subject model. At least this has been my experience.

Hello,

I wrote a little test that loads a model within a model, and works:

The controller mod.php
Code:
<?php
class Mod extends Controller {

  function Mod()
  {
    parent::Controller();
    $this->load->model('testmod');
  }
  function modtest() {
    $this->testmod->test();
  }
}
?>

then two models

testmod.php
Code:
<?php
class Testmod extends Model
{
  function Testmod()
  {
    parent::Model();
    $this->load->model('testmod2');
  }

  function test()
  {
    echo "hello1..";
    $this->testmod2->test();
  }
}
?>

testmod2.php
Code:
<?php
class Testmod2 extends Model
{
  function Testmod2()
  {
    parent::Model();
  }

  function test()
  {
    echo "hello2";
  }
}
?>

when I call

http://localhost/..../index.php/mod/modtest

it prints out:
Code:
hello1..hello2

Is this behavior you would expect?


Messages In This Thread
Loading a model within a model. - by El Forum - 10-30-2007, 04:59 PM
Loading a model within a model. - by El Forum - 10-30-2007, 05:26 PM
Loading a model within a model. - by El Forum - 10-30-2007, 05:35 PM
Loading a model within a model. - by El Forum - 10-30-2007, 08:51 PM
Loading a model within a model. - by El Forum - 10-30-2007, 11:44 PM
Loading a model within a model. - by El Forum - 10-31-2007, 05:28 AM
Loading a model within a model. - by El Forum - 10-31-2007, 12:08 PM
Loading a model within a model. - by El Forum - 10-31-2007, 12:11 PM
Loading a model within a model. - by El Forum - 10-31-2007, 01:45 PM
Loading a model within a model. - by El Forum - 10-31-2007, 01:54 PM
Loading a model within a model. - by El Forum - 10-31-2007, 02:26 PM
Loading a model within a model. - by El Forum - 10-31-2007, 02:27 PM
Loading a model within a model. - by El Forum - 10-31-2007, 03:58 PM
Loading a model within a model. - by El Forum - 10-31-2007, 04:10 PM
Loading a model within a model. - by El Forum - 10-31-2007, 04:26 PM
Loading a model within a model. - by El Forum - 10-31-2007, 05:03 PM
Loading a model within a model. - by El Forum - 11-02-2007, 04:34 AM
Loading a model within a model. - by El Forum - 11-02-2007, 07:14 AM
Loading a model within a model. - by El Forum - 11-02-2007, 12:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB