为什么我在CakePhP 3.0中找到"TableRegistry not found"?

Joe*_*e C 4 mysql cakephp-3.0

我有一个充满静态函数的类,我在Model /目录中调用UtilityFunctions.但即使"use"语句到位,该类也无法访问TableRegistry :: Get.下面是代码和错误.

namespace App\Model\Table;
use Cake\ORM\TableRegistry;
use App\Model\Entity\Device;

class UtilityFunctions {
    public static function getDevice($deviceInfo) {
        $devicesTable = TableRegistry::get('Devices'); // TableRegistry not found
        $query = $devicesTable->findByDeviceInfo($deviceInfo);
       ...
    }
}
Run Code Online (Sandbox Code Playgroud)

"Class\u0027UtilityFunctions\TableRegistry\u0027 not found","/ var/www/myserver/src/Model/Custom/UtilityFunctions.php",115

Nat*_*jar 9

我知道这可能是一个非常晚的回复,但是如果您没有插入use Cake\ORM\TableRegistry;代码的顶部,可能会出现问题.

我遇到过同样的问题.我添加了那行代码并且工作正常