2011-08-16 10 views
2

여기서 리디렉션이 작동하지 않는 이유는 무엇입니까? 정의되지 않은 함수 redirect()가 호출됩니다.Codeigniter 리디렉션이 작동하지 않습니다.

class Login extends CI_Controller { 

    function index() { 

     parent::__construct(); 
     $this->load->helper('form'); 
     $this->load->helper('url'); 
     $this->load->view('login_view');   

    } 

    function authenticate() { 

     $this->load->model('user_model'); 
     $query = $this->user_model->authenticate(); 

     if($query) { 

      $data = array(
       'username' => $this->input->post('username'), 
       'is_logged_in' => true 
      ); 

      $this->session->set_userdata($data); 
      redirect('/site/news_feed'); 

     } 
     else { 

      $this->index(); 

     } 

    } 

} 

답변

14

변경이 귀하의 authenticate() 방법 위의 상단 부분 ...

class Login extends CI_Controller { 

    function __construct() 
    { 
     // this is your constructor 
     parent::__construct(); 
     $this->load->helper('form'); 
     $this->load->helper('url'); 
    } 

    function index() 
    { 
     //this is only called when someone does not specify a method... 
     $this->load->view('login_view');   
    } 
... 

나는 것 강하게 ...이 두 도우미가 때문에 거의 manditory 사용으로 자동으로 적재하는 이동 추천

2

당신은 authenticate 방법에 URL 헬퍼를로드 아닙니다. 당신은 (당신이하려고했던 것처럼 보이는) 클래스 생성자에 $this->load->helper('URL')을 추가하거나, 그것을 authenticate 메소드 자체에 추가해야합니다.

index 메서드는 특별한 메서드입니다. 다른 메서드를 지정하지 않으면이 메서드가 호출됩니다. URL이 <your domain>/login/ 인 경우 색인이 실행됩니다. 그 외에는 무시됩니다.

0

귀하의 논리 바로 inda입니다. 그러나 생성자에서 일부 도우미와 모델을로드 할 때 몇 가지 단점이 있습니다. 가끔 있습니다.

함수 내에서 도우미로드를 시도하십시오.

+0

이러한 "단점"의 예는 무엇입니까? – jondavidjohn

2

시도 :

는 서버가 창입니다
function __construct() { 
    parent::__construct(); 
    $this->load->helper('form'); 
    $this->load->helper('url'); 
} 

경우, 시도 :

redirect('/site/news_feed','refresh'); 
0

당신은 당신의 리디렉션 기능을하기 전에

$this->load->helper('url'); 

을 배치해야합니다.

관련 문제