2013-12-12 14 views
0

嗨,那么你怎么做到kohana 3.3和kostache?匹配url到标题页

<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"; 
} 

胡子模板

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

到目前为止好,我现在在个人资料页,但网址是

localhost/kohana_app/user/login 

,而不是

localhost/kohana_app/user/profile 

我知道我可以改变action_loginaction_profile以匹配网址和页面标题,但有没有其他方法可以做到这一点?

回答

1

如果登录成功并重定向到配置文件页面,请忘记响应正文。

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

请阅读Post/Redirect/Get


例路线(S)的要求

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'); 
     } 

     // ... 
    } 
} 

个人而言,我喜欢我的用户发送到仪表盘,它可以是(来自)查看自己的个人资料不同。

这只是A这样做。

+0

因此,为此,我需要在引导文件中设置另一条路径?是的,然后在我的个人资料页面上使用它。 – Defyleiti

+0

http://kohanaframework.org/3.3/guide/kohana/tips#dont-try-and-use-one-route-for-everything您可以做的最好的事情是删除'默认'示例路线并创建更具体的路线。赶上所有路线都不好。所以如果可以的话,尽量避免它们,它看起来像你从头开始,所以你没有任何借口:p再次:删除'默认'路线。 – Darsstar

+0

好的,非常感谢这个想法。我真的很感谢你的帮助:) – Defyleiti