2017-01-25 8 views
0

동일한 컨트롤러 내의 다른 기능에 대한 액세스 권한이없는 경우 컨트롤러 인덱스로 리디렉션하려고합니다. 내 코딩에 따르면 그것은 무한 루프처럼 보입니다. 제발 저를 도와주세요.codeigniter에서 유효성 검사가 실패한 경우 특정 컨트롤러 기능으로 리디렉션

class Customer_Dashboard extends CI_Controller { 
    public function __construct() { 
     $method= $this->router->fetch_method(); 
     if ($this->session->userdata("cus_sel_comp")) { 

     }else{ 
      if($method !="index"){ 
       redirect(base_url()."customer_dashboard");exit; 
      } 
     } 
    } 
    public function index() { 
     // Here do some operations and let the user to select company and update the "cus_sel_comp" session variable. After set that session user can access the other controller functions. 
    } 
    public function other_function1() { 

    } 
    public function other_function2() { 

    } 
} 

위와 동일합니다. 같은 컨트롤러를 사용하여이 작업을 수행해야합니다. 문제는 그 세션이 무한 루프로 설정되어 있지 않다는 것입니다.

답변

0

반환 색인 기능을 리디렉션하는 대신. 아래 코드를 참조하십시오.

if($method !="index"){ 
       return $this->index(); 
} 
0

동일한 기능을 호출하고 같은 방법으로 리디렉션하고 있습니다.

class Customer_Dashboard extends CI_Controller { 
     public function __construct() { 
      $method= $this->router->fetch_method(); 
      if ($this->session->userdata("cus_sel_comp")) { 

      }else{ 
       if($method !="index"){ 
        redirect(base_url()."Customer_Dashboard/index"); // Redirect it to index if other method is invoked. 
       } 
      } 
     } 
     public function index() { 
      // Here do some operations and let the user to select company and update the "cus_sel_comp" session variable. After set that session user can access the other controller functions. 
     } 
     public function other_function1() { 

     } 
     public function other_function2() { 

     } 
    } 

또한 설정에 경로를 정의하는 대신 그 base_url()을 사용하지 말아 base_url() 않은 반드시라고 존재하는 다른 많은 항목이 있습니다.

+0

저에게 해답을 줄 수 있습니까? –

+0

@GayanFernando가 리디렉션과 관련하여 질문에 답변 해 주셨습니다. 당신은 그것 또는'base_url' 하나를위한 해결책을 묻고 있습니까? –

+0

customer_dashboard 컨트롤러 색인 기능으로 리디렉션해야합니다. 사이트 메인 컨트롤러가 아닙니다. 그렇게 할 수 있습니까? 아니면 리디렉션을 사용하는 것 이외의 다른 방법을 사용할 수 있습니까? –