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

Wednesday, January 19, 2022

[FIXED] Cannot call plugin Controllers in Cakephp

 January 19, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

I have a plugin named as PanelAdmin. It has Controller UsersController.php and inside it there are different actions defined. I have called the default controller within the plugin through this code

$routes->connect('/PanelAdmin', ['plugin' => 'PanelAdmin','controller' => 'default','action' => 'index']);

but cannot call other controller if i hit this url:

http://localhost/multi_shopping/PanelAdmin/Users/

One thing more i want to clear is i have to define routes for all controllers actions in routes.php. Please solve my issue. Thanks


Solution

In your plugin routes.php make sure you are setting a fallback route.

routes.php

<?php
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;

Router::plugin(
    'PanelAdmin',
    ['path' => '/PanelAdmin'],
    function (RouteBuilder $routes) {
        $routes->fallbacks(DashedRoute::class);
    }
);

From the DashedRoute class:

/**
 * This route class will transparently inflect the controller, action and plugin
 * routing parameters, so that requesting `/my-plugin/my-controller/my-action`
 * is parsed as `['plugin' => 'MyPlugin', 'controller' => 'MyController', 'action' => 'myAction']`
 */


Answered By - Reactgular
  • 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