PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, March 13, 2022

[FIXED] using FactoryLocator didnt work as class not found with cakephp4.2

 March 13, 2022     cakephp     No comments   

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

https://marketplace.visualstudio.com/search?term=php&target=VSCode&category=All%20categories&sortBy=Relevance

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.

enter image description here



Answered By - Salines
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing