在cakephp4.2中找不到使用FactoryLocator的类时,使用FactoryLocator不起作用

在cakephp4.2中找不到使用FactoryLocator的类时,使用FactoryLocator不起作用,cakephp,Cakephp,在CakePHP4.2中使用模型访问模型时,docs命令FactoryLocator不起作用 Class 'App\Model\Table\FactoryLocator' not found use Cake\ORM\TableLocator; //tried this use Cake\Datasource\Locator\LocatorInterface; //tried this class LessonsTable extends Table public function ge

在CakePHP4.2中使用模型访问模型时,docs命令FactoryLocator不起作用

Class 'App\Model\Table\FactoryLocator' not found

use Cake\ORM\TableLocator;  //tried this
use Cake\Datasource\Locator\LocatorInterface; //tried this

class LessonsTable extends Table
 public function getTest1(){
   $clients = FactoryLocator::get('Table')->get('Clients'); //error here 



https://book.cakephp.org/4/en/orm/table-objects.html#using-the-tablelocator
https://api.cakephp.org/4.1/class-Cake.Datasource.FactoryLocator.html
再说一遍;)

使用Cake\Datasource\FactoryLocator;//获取(“客户”);
我不知道您是在哪个编辑器中编写php代码的,但我建议您使用插件来建议当前php文件中有哪些php/cakephp方法可用

例如,在中添加一些extennion,如

用于代码完成使用

然后,当您键入
FactoryLo
editor查找类/方法并向您提出建议时,如果缺少名称空间,它还会自动添加名称空间


我正在使用netbeans,这有帮助吗?我会考虑你的建议,但如果文件没有澄清这样的事情,那就没用了。
use Cake\Datasource\FactoryLocator; // <--------------- use this

class LessonsTable extends Table
 public function getTest1(){
   $clients = FactoryLocator::get('Table')->get('Clients');