我想在cakephp3中的控制器中的特定函数中加载多个模型?
我试图在cakePhp3中设置$uses,它在cakePhp2.6中工作,但在3中不工作我想在cakephp3中的控制器中的特定函数中加载多个模型?,cakephp,cakephp-3.0,Cakephp,Cakephp 3.0,我试图在cakePhp3中设置$uses,它在cakePhp2.6中工作,但在3中不工作 public $uses = array('model1', 'model2', 'model3', .... ); 但我得到的错误是 { "message": "Call to a member function find() on boolean", "url": "/JobPosts/Test/1042.json", "code": 500, "file": "/ho
public $uses = array('model1', 'model2', 'model3', .... );
但我得到的错误是
{
"message": "Call to a member function find() on boolean",
"url": "/JobPosts/Test/1042.json",
"code": 500,
"file": "/home/task24/public_html/clientApi/src/Controller/JobPostsController.php",
"line": 1304
}
尝试使用数组映射加载所有模型
array_map([$this, 'loadModel'], ['Product', 'Orders', 'OrderItem']); //Pass each element of the array to loadModel with is accessable through $this object.
或者在AppController中创建一个函数,如
function loadModels($models = []) {
foreach($models as $model) {
$this->loadModel($model);
}
}
//Then you can access this function anywhere from any controller function (Controller which are extending AppController)
$this->loadModels(['Products', 'Orders', 'SO-ON']);
在蛋糕3中不再使用
$uses
$this->loadModel('MyModel');
阅读