Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "TableRegistry not found" in CakePhP 3.0?

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

like image 464
Joe C Avatar asked Feb 09 '23 08:02

Joe C


1 Answers

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

like image 93
Nathaniel Cutajar Avatar answered Feb 12 '23 11:02

Nathaniel Cutajar