CakePHP:调用其他Model函数 [英] CakePHP: calling other Model functions
本文介绍了CakePHP:调用其他Model函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从模型中调用另一个模型中存在的函数?我不想重复代码。
How can i call, from a Model, a function present in another model? I would like not to repeat code.
推荐答案
我们可以使用Model关系调用另一个模型中的函数。例如
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();
直接加载该模型。
这篇关于CakePHP:调用其他Model函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文