簡體   English   中英

匹配標題頁面的URL

[英]matching url to title page

嗨,您如何在kohana 3.3和kostache中進行操作?

形成

<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相匹配的URL和頁面的標題,但是否有任何其他方式做到這一點?

如果登錄成功,則忽略響應的正文,然后重定向到配置文件頁面。

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

閱讀Post / Redirect / Get


要求的路線示例

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

        // ...
    }
}

我個人喜歡將用戶發送到儀表板,該儀表板可能與查看您自己的個人資料不同。

這只是這樣做的一種方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM