2012-04-03 3 views
0

동일한 컨트롤러 APP/컨트롤러에 account.php와 address.php 컨트롤러가 2 개 있습니다. 첫 번째 컨트롤러 인 account.php의 경우 다음과 같이 URI에 대한 기본 라우터를 사용합니다. account/create, account/login, account/logout ... 두 번째 컨트롤러를 작성할 때 account.add와 함께 address.php의 모든 URI를 사용하고 싶습니다. /. 여기에서 볼 수 있듯이 계정 컨트롤러와 일치하는 동일한 URI 라우터를 사용하고 있습니다.Kohana 3.2 접두어 URI가있는 컨트롤러 용 라우터는 다른 컨트롤러에 속합니다.

내 첫 번째 방법 :

// Add new address 
Route::set('address', 'account/address/<action>') 
     ->defaults(array(
       'controller' => 'address', 
       'action'  => 'index', 
     )); 

내 주소 컨트롤러는

public function before() 
{ 
    parent::before(); 

    if (! Auth::instance()->logged_in()) 
    { 
     // Redirect to a login page (or somewhere else). 
     $this->request->redirect(''); 
    } 
} 



// nothing here 
public function action_index() 
{ 
    $this->request->redirect(''); 
} 


// create account 
public function action_create() 
{ 

    // Create an instance of a model 
    $profile = new Model_Address(); 

    // received the POST 
    if (isset($_POST) && Valid::not_empty($_POST)) 
    { 

     // // validate the form 
     $post = Validation::factory($_POST) 
     ->rule('firstname', 'not_empty') 
     ->rule('lastname', 'not_empty') 
     ->rule('address', 'not_empty') 
     ->rule('phone', 'not_empty') 
     ->rule('city', 'not_empty') 
     ->rule('state', 'not_empty') 
     ->rule('zip', 'not_empty') 
     ->rule('country', 'not_empty') 
     ->rule('primary_email_address', 'email'); 

     // if the form is valid and the username and password matches 
     if ($post->check()) 
     { 

      if($profile->create_profile($_POST)) 
      { 
       $sent = kohana::message('profile', 'profile_created'); 
      } 

     } else { 
      // validation failed, collect the errors 
      $errors = $post->errors('address'); 
     } 

    } 

    // display 
    $this->template->title = 'Create new address'; 
    $this->template->content = View::factory('address/create') 
      ->bind('post', $post) 
      ->bind('errors', $errors) 
      ->bind('sent', $sent); 
} 

이 확인 될 것으로 보인다하지만, 라우터 계정/주소/작동하지 않습니다 만듭니다. Kohana는 해당 URI에 대해 404 메시지를 발생시킵니다.

왜 이런 일이 발생하는지 알고 계십니까?

답변

4

시스템에서 경로를 확인한 결과 정상적으로 작동하므로 다른 곳에서 오류가 발생했다고 가정합니다. 컨트롤러 클래스 이름은 Controller_Address입니다 확인하는 경우도 docs 말하는대로, 부트 스트랩에서 첫 번째로이 경로를 배치하려고 :

이 루트는 순서 그들이에 일치하는 것을 이해하는 것이 중요하다 URL이 경로와 일치하자마자 라우팅은 이 본질적으로 "중지됨"이며 나머지 경로는 절대로 시도되지 않습니다. 기본 경로가 빈 URL을 포함하여 거의 모든 경로와 일치하기 때문에 경로 앞에 새로운 경로가 있어야합니다.

또 다른 문제는 질문과 관련이 없습니다. 모델에 유효성 검사를해야합니다. 컨트롤러가 그 장소가 아닙니다;)

+0

굉장한 남자, 최우선 순위에 넣는 것이 트릭입니다. 그리고 네, 맞습니다. 유효성 검사가 모델에 대신 있어야합니다. 그러면 컨트롤러가 깨끗하고 읽기 쉽게 보이게됩니다. – lnguyen55

관련 문제