将url与标题页匹配



嗨,你是如何在kohana 3.3和kostach中做到这一点的?

表单

<form method="POST" action="user/login">
<input type="text" name="email" />
<input type="passowrd" name="password" />
</form>

控制器

 public function action_login()
 {
   $user = Auth::instance()->login($this->request->post('email'),$this->request->post('password'));
   if($user)
   {
       $view = Kostache_Layout::factory()
       $layout = new View_Pages_User_Info();
       $this->response->body($this->view->render($layout));
   }
   else
   {
       $this->show_error_page();
   }
 }

类视图

class View_Pages_User_Info
{
    public $title= "Profile";
}

Mustache模板

   <p> This is the Profile Page</p>

到目前为止还不错,我现在在个人资料页面,但网址是

localhost/kohana_app/user/login 

而不是

localhost/kohana_app/user/profile

我知道我可以将action_login更改为action_profile以匹配url和页面标题,但有其他方法吗?

如果登录成功,则忽略响应的正文,并重定向到配置文件页面。

HTTP::redirect(Route::get('route that routes to the profile page')->uri(/* Just guessing */'action' => 'profile'));

阅读帖子/重定向/获取。


请求的路线示例

Route::set('home', '')
    ->defaults(array(
        'controller' => 'Home',
    ));
Route::set('auth', 'user/<action>', array('action' => 'login|logout'))
    ->defaults(array(
        'controller' => 'User',
    ));
Route::set('user/profile/edit', 'user/profile/edit(/<user>)')
    ->defaults(array(
        'controller' => 'User_Profile', // Controller_User_Profile
        'action' => 'edit',
    ));
Route::set('user/profile/view', 'user/profile(/<action>(/<user>))', array('action' => 'edit'))
    ->defaults(array(
        'controller' => 'User_Profile',
    ));
############
class Controller_User_Profile {
    public function action_index()
    {
        // ...
        $this->action_view($user->username());
    }
    public function action_view($user = NULL)
    {
        if ($user === NULL)
        {
            $user = $this->request->param('user');
        }
        // ...
    }
}

就我个人而言,我喜欢将我的用户发送到仪表板,这可能与查看您自己的个人资料不同。

这只是一种方式。

最新更新