Cakephp Routes And General Routing

最后都变了- 提交于 2019-12-13 07:17:10

问题


I have a controller with an action and a variable like this:

 class AccountsController extends AppController
 {
      function profile($username = null)
     {
     }
 }

The url for this page is:

 [domain]/accounts/profile/[username]

How do I make it:

 [domain]/[username]

?


回答1:


Try:


//in your routes.php file
Router::connect('/:username',
array('controller' => 'accounts', 'action' => 'profile'),
  array(
      'pass' => array('username')
  )
);

Hope it helps



来源:https://stackoverflow.com/questions/8753671/cakephp-routes-and-general-routing

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