CakePHP: calling other Model functions

前端 未结 7 630
感动是毒
感动是毒 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:34

    We can use Model relation to call the function in another model. Eg.

    $this->Model->ModelOne->find();
    $this->Model->ModelOne->customFunc();
    

    If there is no relation in the models, The we can use

    $this->loadModel('ModelName');
    

    To use in the model. In this case you can use

    $this->ModelName->function();
    

    directly as you've loaded that model.

    0 讨论(0)
提交回复
热议问题