我正在开发Kohana PHP框架。
我想在URL中显示'username'而不是控制器名称。
例如,username = James then how to show
http://localhost: 3000/詹姆斯
不是http://localhost:3000/scrapbook/index =>…localhost: 3000/剪贴簿
(controller: scrapbook, action: index)
我的引导文件有这类url的条目。如果我手工写。//localhost:3000/james,它把我带到请求的页面。
//Viewing a user's profile or account details - user/action
Route::set('profile', '(<username>(/<action>(/<id>)))',
array(
'username' => '([A-Za-z0-9'-]+)'))
->defaults(array(
'controller' => 'scrapbook',
'action' => 'index'));
我想要的是,如果我手动登录并去剪贴簿,我的url应该显示'用户名',而不是控制器的名称。如果有人能在这方面指导我,我会很感激。由于
当您完成登录操作时,您将希望使用反向路由将用户重定向到所需的URL:
// ...in your controller
function action_signin()
{
// ...sign in logic
$this->request->redirect(
Route::get('profile')->uri(array(
'username' => $username
))
);
}
$username
将是刚刚登录的用户的用户名