CakePHP:调用其他模型函数 [英] CakePHP: calling other Model functions

查看:28
本文介绍了CakePHP:调用其他模型函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从一个模型调用另一个模型中存在的函数?我不想重复代码.

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

推荐答案

我们可以使用模型关系来调用另一个模型中的函数.例如.

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:调用其他模型函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆