问题
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