Cakephp routes prefix

三世轮回 提交于 2019-12-20 06:09:01

问题


I have 3 diferent layouts for my application related to diferent parts of content. I vould like to define my url-s so they would have the part in the begining ex. "mypage.com/part1/controller/...". I don't know how to change routes to make this possible.

P.S. I don't want ordinary prefix routing where names of my controller actions would have changed.


回答1:


read below url

For CakePHP 2.x http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing

For CakePHP 1.x http://bakery.cakephp.org/articles/Frank/2009/11/02/cakephp-s-routing-explained

Or

Configure::write('Routing.prefixes', array('admin', 'manager'));

$this->connect("/{$prefix}/:plugin/:controller", array('action' => 'index', 'prefix' => $prefix, $prefix => true));
$this->connect("/{$prefix}/:plugin/:controller/:action/*", array('prefix' => $prefix, $prefix => true));
Router::connect("/{$prefix}/:controller", array('action' => 'index', 'prefix' => $prefix, $prefix => true));
Router::connect("/{$prefix}/:controller/:action/*", array('prefix' => $prefix, $prefix => true));



回答2:


It's very easy to integrate multiple prefix with routing in cakephp

In cakephp 2.x you have to go through following steps

  1. go to the app/Config/core.php and add following lines Configure::write('Routing.prefixes', array('admin','manager'));
  2. Now you have to write the routing for this go to the app/Config/routes.php add following lines
  3. Router::connect("admin/:controller",array('action'=>'index','admin'=>true));
  4. Router::connect("admin/:controller/:action/*",array('admin'=>true));
  5. Router::connect("manager/:controller",array('action'=>'index','manager'=>true));
  6. Router::connect("manager/:controller/:action",array('manager'=>true));

For more info refer following link http://book.cakephp.org/2.0/en/development/routing.html http://miftyisbored.com/complete-tutorial-admin-routing-cakephp/



来源:https://stackoverflow.com/questions/11705107/cakephp-routes-prefix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!