Cakephp Routes And General Routing

2019-09-09 12:16发布

问题:

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