2013-12-12 4 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> 

지금까지 너무 좋아, 나는 프로필 페이지에서 지금이야하지만 URL이 나는이를 변경할 수 있습니다 알고

localhost/kohana_app/user/login 

대신

localhost/kohana_app/user/profile 

입니다 action_login ~ action_profile은 URL과 페이지 제목과 일치하지만 다른 방법이 있습니까?

답변

1

로그인이 성공하고 프로필 페이지로 리디렉션되면 응답 시체를 잊어 버립니다.

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

     // ... 
    } 
} 

는 개인적으로 내가 자신의 프로필을 볼 다를 수 (온) 수있는 대시 보드, 내 사용자를 보내려고 요청으로


예 경로 (들).

이것은 단지 입니다.

+0

이렇게하려면 부트 스트랩 파일에 다른 경로를 설정해야합니까? 그렇다면 내 프로필 페이지에서 사용하십시오. – Defyleiti

+0

http://kohanaframework.org/3.3/guide/kohana/tips#dont-try-and-use-one-route-for-everything 가장 좋은 방법은 '기본'예제 경로를 삭제하고 더 구체적인 경로를 만드는 것입니다. 노선. 모든 경로를 잡아라. 그렇게 할 수 있으면 피하십시오. 처음부터 시작하는 것처럼 보이므로 변명의 여지가 없습니다. 다시 : '기본'경로를 삭제하십시오. – Darsstar

+0

아이디어에 대해 감사드립니다. 정말 고마워 도움을 주셔서 감사합니다 :) – Defyleiti