2017-01-25 11 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コントローラインデックス関数にリダイレクトする必要があります。サイトメインコントローラ用ではありません。それは可能ですか?それ以外に、リダイレクト以外の方法がありますか? –

関連する問題