Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp use another model inside current model

I know I can use another model inside a controller by doing $this->loadModel("MyModel"), but how do I do this inside another Model? I tried to use loadModel but it didn't work.

Any idea?

Thank you

like image 342
user765368 Avatar asked Mar 13 '12 20:03

user765368


2 Answers

Easier is:

$my_model = ClassRegistry::init('MyModel');

More details: Can I use one model inside of a different model in CakePHP?

like image 115
Costa Avatar answered Oct 20 '22 01:10

Costa


You can use the following code to export a model that is not associated with the current model in any way:

App::import('Model', 'MyModel');
$my_model = new MyModel();

If MyModel is associated with current model you could use the chaining e.g. $this->SomeModel->MyModel

like image 23
Ehtesham Avatar answered Oct 20 '22 01:10

Ehtesham