本文介绍了为什么我会收到“找不到TableRegistry"的消息?在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);
       ...
    }
}

未找到类\ u0027UtilityFunctions \ TableRegistry \ u0027","/var/www/myserver/src/Model/Custom/UtilityFunctions.php",115

解决方案

我知道这可能是一个很晚的答复,但可能是您未在代码顶部插入use Cake\ORM\TableRegistry;所致. >

我有同样的问题.我添加了那行代码,它就可以了

I have a class full of static functions that I call UtilityFunctions in my Model/ directory. But that class cannot access TableRegistry::Get even though the "use" statements are in place. Below is the code and the error.

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);
       ...
    }
}

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

解决方案

I know that this might be a really late reply, but it may be an issue with you not inserting use Cake\ORM\TableRegistry; at the top of the code.

I had the same issue. I added that line of code and it worked

这篇关于为什么我会收到“找不到TableRegistry"的消息?在CakePhP 3.0中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:02