Cakephp Routes And General Routing

2019-09-09 12:29发布

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条回答
聊天终结者
2楼-- · 2019-09-09 13:11

Try:


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

Hope it helps

查看更多
登录 后发表回答