cakephp - Can i hide controller and view name cake php 2? -


i using cake php , due reason want hide controller , action name url . current url

http://192.168.1.31/home/this_is_test

where home controller name , this_is_test slug dynamic . want url

http://192.168.1.31/this_is_test.

my routes.php

router::connect('/', array('controller' => 'home', 'action' => 'index')); router::connect('/dashboard', array('controller' => 'dashboard', 'action' => 'index')); router::connect('/login', array('controller' => 'users', 'action' => 'login')); router::connect('/admin/login', array('controller' => 'users', 'action' => 'login', 'admin' => true)); router::connect('/contents/*', array('controller' => 'contents', 'action' => 'view')); router::connect('/home/*', array('controller' => 'home', 'action' => 'index')); 

i have read couple of solution after googling . tried in routes.php . no luck

router::connect(     '/:query',    array('controller' => 'home', 'action' => 'index',1),     array('query' => '[a-za-z]+') ); 

anybody have idea if possible??

your solution

for static text try this:

router::connect('/this_is_test', array(       'controller' => 'home',        'action' => 'this_is_test or any_other action name' )); 

if it's dynamic

router::connect('/:id',      array('controller' => 'home', 'action' => 'index'),     array(         'pass' => array('id'),         array('id' => '[a-za-z]')     ) ); 

references: cakephp2.x route

i hope knew want achieve. can place route in last position. here reference .

other option use alias controller. call controller thing else , set new name controller call in route.

if doesn't work need write bespoke component in order that.


Comments