CakePHP routing in pages controller

醉酒当歌 提交于 2019-12-04 18:58:49

You're passing only one parameter to the action via routing, that's why it's the first one - its the only one. Names don't really matter.

I would do it like this:

Router::connect(
  '/:page',
  array('controller' => 'pages', 'action' => 'display'),
  array('pass' => array('page'), 'page' => '[a-z]+')
  ); 
Router::connect(
  '/special/:mypage',
  array('controller' => 'pages', 'action' => 'display_special'),
  array('pass' => array('page'), 'page' => '[a-z]+')
  );

Controller code:

function display($page) {}
function display_special($page) {}

But if you want your way, try this:

Router::connect(
  '/:special/:mypage',
  array('controller' => 'pages', 'action' => 'display'),
  array('pass' => array('special', 'mypage'), 'mypage' => '[a-z]+')
  );

Actually I have discovered that the pages controller already handles this situation, checking for page and subpage. The URL mysite.com/special/mypage points to app/views/pages/special/mypage.ctp with the only rule

Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!