简体   繁体   English

匹配标题页面的URL

[英]matching url to title page

Hi so how do you do it in kohana 3.3 and kostache? 嗨,您如何在kohana 3.3和kostache中进行操作?

Form 形成

<form method="POST" action="user/login">

<input type="text" name="email" />
<input type="passowrd" name="password" />

</form>

Controller 调节器

 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 类视图

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

Mustache Template 小胡子模板

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

So far so good, I'm now in the profile page but the url is 到目前为止一切顺利,我现在在个人资料页面中,但网址为

localhost/kohana_app/user/login 

instead of 代替

localhost/kohana_app/user/profile

I know I can change the action_login to action_profile to match the url and the title of the page but is there any other way to do this? 我知道我可以改变action_loginaction_profile相匹配的URL和页面的标题,但是否有任何其他方式做到这一点?

Forget about a body for the response if the login was succesful and redirect to the profile page. 如果登录成功,则忽略响应的正文,然后重定向到配置文件页面。

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

Read up on Post/Redirect/Get . 阅读Post / Redirect / Get


Example route(s) as requested 要求的路线示例

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

        // ...
    }
}

Personally I like to send my users to a dashboard, which can be(come) different from viewing your own profile. 我个人喜欢将用户发送到仪表板,该仪表板可能与查看您自己的个人资料不同。

This is just A way of doing it. 这只是这样做的一种方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM