Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在cakephp3中的控制器中的特定函数中加载多个模型?_Cakephp_Cakephp 3.0 - Fatal编程技术网

我想在cakephp3中的控制器中的特定函数中加载多个模型?

我想在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

我试图在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": "/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');
阅读