Cakephp uses a different model inside the current model

I know that I can use another model inside the controller by doing $this->loadModel("MyModel") , but how to do it in another model? I tried using loadModel, but that did not work.

Any idea?

thanks

+6
source share
3 answers

Easier:

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

More: Can I use one model inside another model in CakePHP?

+21
source

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

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

If MyModel is associated with the current model, you can use a chain, for example. $this->SomeModel->MyModel

+4
source

You do not need to import anything. Just do the following:

 $my_model = new MyModel(); //Then $my_model->read(null,$id); 
0
source

Source: https://habr.com/ru/post/910633/


All Articles