gpt4 book ai didi

CakePHP:调用其他模型函数

转载 作者:行者123 更新时间:2023-12-04 00:16:44 26 4
gpt4 key购买 nike

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

最佳答案

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

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

如果模型中没有关系,我们可以使用
$this->loadModel('ModelName');

在模型中使用。
在这种情况下,您可以使用
$this->ModelName->function();

直接在您加载该模型时。

关于CakePHP:调用其他模型函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7204591/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com