我想在 cakephp 3 的控制器中的特定功能中加载多个模型?

i want to load multiple models in a particular function in a controller in cakephp3?

我尝试在 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函数加载所有模型

array_map([$this, 'loadModel'], ['Product', 'Orders', 'OrderItem']);   //Pass each element of the array to loadModel with is accessable through $this object.

或者在您的 A​​ppController 中创建一个函数,例如

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']);

你不再在 Cake 3 中使用 $uses

$this->loadModel('MyModel');