使用 Factory Locator 无效,因为 class 在 cakephp 4.2 中找不到
using FactoryLocator didnt work as class not found with cakephp4.2
在 cakephp 4.2 中访问模型中的模型时,文档命令 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
再次;)
use Cake\Datasource\FactoryLocator; // <--------------- use this
class LessonsTable extends Table
public function getTest1(){
$clients = FactoryLocator::get('Table')->get('Clients');
我不知道你在哪个编辑器中编写 php 代码,但我建议你使用插件来建议哪些 php / cakephp 方法可用当前 php 文件。
例如在https://code.visualstudio.com/中添加一些扩展如
代码完成使用 https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
然后当你键入 FactoryLo
editor find class / method 并向你建议时,如果缺少命名空间,它也会自动添加。
在 cakephp 4.2 中访问模型中的模型时,文档命令 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
再次;)
use Cake\Datasource\FactoryLocator; // <--------------- use this
class LessonsTable extends Table
public function getTest1(){
$clients = FactoryLocator::get('Table')->get('Clients');
我不知道你在哪个编辑器中编写 php 代码,但我建议你使用插件来建议哪些 php / cakephp 方法可用当前 php 文件。
例如在https://code.visualstudio.com/中添加一些扩展如
代码完成使用 https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
然后当你键入 FactoryLo
editor find class / method 并向你建议时,如果缺少命名空间,它也会自动添加。