我可以隐藏控制器和视图名称蛋糕php 2? [英] Can i hide controller and view name cake php 2?
问题描述
我使用蛋糕php,由于某种原因,我想从URL中隐藏控制器和操作名称。当前网址我们喜欢
http://192.168.1.31/ home / this_is_test
其中home是控制器名称, this_is_test
是slug,我想要像
这样的网址 http://192.168.1.31/this_is_test 。
我的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'=>'content','action'=>'view'));
Router :: connect('/ home / *',array('controller'=>'Home','action'=>'index'));
我在googling之后已经读了几个解决方案。也试过这个在routes.php。但没有运气
Router :: connect(
'/:query',
array '=>'Home','action'=>'index',1),
array('query'=>'[a-zA-Z] +')
);
任何人都有这个想法,如果可能的话
对于静态文本,请尝试:
Router :: connect('/ this_is_test',array(
'controller'=>'home',
'action'=>'this_is_test OR any_other action name'
));
如果是动态的
Router :: connect('/:id',
array('controller'=>'home','action'=>'index'),
array
'pass'=> array('id'),
array('id'=>'[A-Za-z]')
)
);
我希望我知道你真正想要实现的。您可以将路线放置在最后一个位置。 以下是参考资料。
其他选项将为您的控制器使用别名。所以你打电话给你的控制器一些东西,并为你的控制器设置一个新的名称,然后调用它在你的路线。
如果这不起作用,那么您需要编写一个定制的组件,以帮助您。
I am using cake php and due to some reason i want to hide controller and action name from the url . current url us like
http://192.168.1.31/home/this_is_test
where home is controller name and this_is_test
is slug which is dynamic . i want the url like
http://192.168.1.31/this_is_test.
my routes.php is
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 a couple of solution after googling . also tried this in routes.php . but no luck
Router::connect(
'/:query',
array('controller' => 'Home', 'action' => 'index',1),
array('query' => '[a-zA-Z]+')
);
anybody have idea about this if it is 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]')
)
);
I hope I knew what you really want to achieve. You can place the Route in the last position. Here is the reference .
Other option would be to use alias for your controller. So you call your controller some thing else and set a new name for your controller then call it in you Route.
If this doesn't work then you would need to write a bespoke Component in order to help you to do that.
这篇关于我可以隐藏控制器和视图名称蛋糕php 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!