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

Monday, February 21, 2022

[FIXED] Cakephp 3 Default Model not loaded in controller

 February 21, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

I have a controller name CodeBridgeController and have a model table name CodeBridgeTable. When I call CodeBridge table in action like following:

$this->CodeBridge->find('all')->toArray();

This generate Error: Call to a member function find() on a non-object File D:\php\htdocs\cake3\erp\src\Controller\CodeBridgeController.php Line: 25 I think this is silly matter but i could not find any wrong in the code why table is not loaded in this context. When i call this way it works.

$codeBridgeTable = TableRegistry::get('CodeBridge'); $results = $codeBridgeTable->find('all')->hydrate(false)->toArray();

What may create the problem, expert suggestion needed.


Solution

Finally, I found where the problem lies. In controller action, I generating a url like following: Router::url(array('controller' =>'codebridge','action'=>'edit')); which generate url /cake3/erp/codebridge/edit

After changing the controller name in camel case Router::url(array('controller' =>'CodeBridge','action'=>'edit')); which generate url '/cake3/erp/code-bridge/edit`

This solve the problem



Answered By - karim_fci
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

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