doushitang4276 2013-12-12 05:26
浏览 42
已采纳

将网址与标题页匹配

Hi so how do you do it in kohana 3.3 and 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?

  • 写回答

1条回答 默认 最新

  • douzhi9921 2013-12-12 07:09
    关注

    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.


    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?