CakePHP在URL中隐藏动作名称,同时传递参数 [英] CakePHP hiding action name in URL, while passing arguments
问题描述
我有这样的结构:
- example.com / MyController / index / MyGoodPage / maximum /
- example.com / MyController / index / MyBestPage / optimum /
- example.com / MyController / index / MyFancyPage / lowprice /
但我不希望我的访问者看到索引字,因为它不给他/她提供任何更多的信息。我需要我的网址,例如:
- example.com / MyController / MyGoodPage / maximum /
- example.com / MyController / MyBestPage / optimum /
- example.com / MyController / MyFancyPage / lowprice /
$ b b
但是在默认的Cake-way中,我需要创建单独的动作来处理我的情况。我不想创建所有操作,我需要创建一个操作,然后显示有关 request-> params ['pass]]
的相关内容。 p>
是否有可能?
这是路由的工作: a href =http://book.cakephp.org/2.0/en/development/routing.html =nofollow> http://book.cakephp.org/2.0/en/development/routing.html
,这实际上是核心PagesController的显示
方法默认做的:
Router :: connect('/ pages / *',array('controller'=>'pages','action'=>'display'));
您也可以为您的控制器执行相同操作
Router :: connect('/ controller_name / *',array('controller'=>'index_name','action'=>'index'));
I have such a structure:
- example.com / MyController / index / MyGoodPage / maximum/
- example.com / MyController / index / MyBestPage / optimum/
- example.com / MyController / index / MyFancyPage / lowprice/
But I don't want my visitors to see "index" word, because it doesn't give any more information to him/her. I need my URLs like this:
- example.com / MyController / MyGoodPage / maximum/
- example.com / MyController / MyBestPage / optimum/
- example.com / MyController / MyFancyPage / lowprice/
But to do thisin default Cake-way, I need to create seperate hundereds of actions to handle my situation. I don't want to create them all actions, I need to create one action and then show relevant content regarding to request->params['pass']
.
Is it possible?
This is a job for Routing: http://book.cakephp.org/2.0/en/development/routing.html
and this is actually what is done by default for the core PagesController's display
method:
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
You could do the same for your controller
Router::connect('/controller_name/*', array('controller' => 'controller_name', 'action' => 'index'));
这篇关于CakePHP在URL中隐藏动作名称,同时传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!