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

Sunday, January 16, 2022

[FIXED] Missing Controller for a plugin in cakephp 3.6

 January 16, 2022     cakephp, cakephp-3.x, controller     No comments   

Issue

I bake a plugin and created a controller manually it is working on my local server but, when I move the plugin through the and hit the url cake saying the controller is missing at plugin controller location i.e. plugins/TourPackages/src/Controller/TourPackagesController.php the file is exist in the location, but it still saying controller is missing. i'm attaching the screen shot of it. I am facing this issue for other plugin that I have created. location of file

Error for missing controller


Solution

I guess it was issue of routing I have tried multiple combinations of URL for the plugin name and the controller name.

What was done in View (.ctp)

 <?php echo $this->Html->link('<h3>Package Name</h3>', ['controller'=>'TourPackages', 'plugin'=>'TourPackages', 'action'=>'sample'], ['title'=>'Package Name', 'class'=>'', 'escape'=>false]);?>

which generate html like <a href="http://demos.cybershines.com/naturessprout/tour-packages/tour-packages/sample" title="Package Name" class=""><h3>Package Name</h3></a>

In My plugin router the routing code was Router::plugin( 'TourPackages', ['path' => '/tour-packages'], function (RouteBuilder $routes) { $routes->fallbacks(DashedRoute::class); } ); This I changed to

Router::plugin(
'TourPackages',
['path' => '/tour-packages'],
function (RouteBuilder $routes) {
    $routes->get('/tour-packages/tour-packages/*', ['controller' => 'TourPackages']);
    $routes->fallbacks(DashedRoute::class);
}

); it taking the "path" /tour-packages for plugin but the controller as "TourPackages" so when I hit http://demos.cybershines.com/naturessprout/tour-packages/TourPackages/sample cake takes me to the correct location and view. So, I modified the routing code by adding $routes->get('/tour-packages/tour-packages/*', ['controller' => 'TourPackages']); in routing.php and tell cake to execute the TourPackagesController for tour-packages.



Answered By - Parag Chaure
  • 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