Issue
in accessing a model withing a model in cakephp 4.2 the docs command FactoryLocator hasnt worked.
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
Solution
Again ;)
use Cake\Datasource\FactoryLocator; // <--------------- use this
class LessonsTable extends Table
public function getTest1(){
$clients = FactoryLocator::get('Table')->get('Clients');
I don't know in which editor you write php code, but I would recommend that you use plugins that will suggest which php / cakephp methods are available in the current php file.
For example in https://code.visualstudio.com/ add some extesnions like
for code completion use https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
Then when you type FactoryLo editor find class / method and suggest to you, it also automatically adds namespace if it is missing.
Answered By - Salines

0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.