CakePHP: calling other Model functions

前端 未结 7 670
感动是毒
感动是毒 2020-12-31 10:04

How can i call, from a Model, a function present in another model? I would like not to repeat code.

7条回答
  •  情话喂你
    2020-12-31 10:13

    You should try to have relationships between your models. There are many types of relationships which you can read here...

    If you have above said associations, you can access your associated models using:

    $this->Model->OtherModel->function();
    

    If your models are not related in any way, you should use:

    ClassRegistry::init('OtherModel')->function();
    

    You can check out my question on this where I obtained great answers

提交回复
热议问题