使用FactoryLocator不起作用,因为cakephp4.2中找不到类

kyvafyod  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(126)

在cakephp 4.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
cngwdvgl

cngwdvgl1#

再次;)

use Cake\Datasource\FactoryLocator; // <--------------- use this

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

我不知道你用哪个编辑器写php代码,但我建议你使用插件,它会提示在当前的php文件中哪些php / cakephp方法可用。
例如,在https://code.visualstudio.com/中添加一些扩展名,如
https://marketplace.visualstudio.com/search?term=php&target=VSCode&category=All%20categories&sortBy=Relevance
对于代码完成,请使用https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
然后当你键入FactoryLo时,编辑器会找到类/方法并向你建议,如果缺少命名空间,它也会自动添加。

相关问题