Removing controller name from url does not work for multiple controllers in cakephp

I want to remove the controller name from the url. It works for one controller, but it doesn't work for multiple controllers. Here is my code in Route.php:

 Router::connect('videos/:action', array('controller' => 'videos'));
 Router::connect('/:action', array('controller' => 'frontends')); 

      

but when i try to access http://local.tbn24.dev/videos

it shows:

Error: Action video not defined in FrontendsController

which proves the above url is linking

Router::connect('/:action', array('controller' => 'frontends'));

      

I want this url to reach the video controller index function. How to use the config Route::connect()

?

+3


source to share


1 answer


but when i try to access http://local.tbn24.dev/videos

There is no route for this

Of the two routes mentioned, this one does not match the above URL as it is only one segment of the path:

Router::connect('videos/:action', array('controller' => 'videos'));

      

Therefore, it will match the catch all route, and it will be videos

interpreted as an action to look for.

Also note that without a leading slash, the route will not match any query as they will always start with a leading slash.



Route to match only controller name

To define a route to match /videos

- or to define a route to match that specific string:

Router::connect('/videos', array('controller' => 'videos', 'action' => 'index'));

      

Or provide a route with a bounding pattern:

Router::connect(
    '/:controller', 
    array('action' => 'index'),
    array('controller' => 'videos|stuff'),
);

      

For more information on routes, check the documentation for the version of CakePHP you are using.

+1


source







All Articles