2016-09-13 8 views
0

codeigniterのサブフォルダからコントローラを実行する方法。codeigniterにサブフォルダを作成し、それをデフォルトコントローラから呼び出す方法はありますか?

私は試しましたが、次のエラーが表示されます。

enter image description here

+0

は、あなたの質問にroutes.phpのファイルのコードのコードを追加します。 –

+0

$ route ['default_controller']の値は何ですか? –

+0

$ルート['default_controller'] = 'スーパー管理者/ loginvalueue'; – Vinoth

答えて

1

あなたが手順の下に、次のことで、これを行うことができます。

Stpep 1)以下のようなフォルダのコントローラにサブフォルダ"superadmin"を作成します。

controllers/superadmin 

Stpep 2)サブフォルダ"superadmin"ように、コントローラcontrollers/superadmin/loginvalueget.phpを作成

<?php 

class Loginvalueget extends CI_Controller { 

    function index() 
    { 
     die('hello world');  
    } 

} 

?> 

ステップ3)デフォルトのコントローラルートをapplication/config/routes.phpのように変更します。

$route['default_controller'] = 'superadmin/loginvalueget'; 

ステップ4)system/core/Router.php方法以下と_set_default_controller()を置き換える:

protected function _set_default_controller() 
    { 
     if (empty($this->default_controller)) 
     { 
      show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); 
     } 

     // Is the method being specified? 
     $x = explode('/', $this->default_controller); 
     $dir = APPPATH.'controllers'; 
     $dir_arr = array(); 
     foreach($x as $key => $val){    
      if(!is_dir($dir.'/'.$val)){ 
       if(file_exists($dir.'/'.ucfirst($val).'.php')){ 
        $class = $val; 
        if(array_key_exists(($key+1), $x)){ 
         $method = $x[$key+1]; 
        }else{ 
         $method = 'index'; 
        } 
       }else{ 
        show_error('Not found specified default controller : '. $this->default_controller); 
       }     
       break;    
      } 
      $dir_arr[] = $val; 
      $dir = $dir.'/'.$val; 
     } 
     //set directory 
     $this->set_directory(implode('/', $dir_arr)); 

     $this->set_class($class); 
     $this->set_method($method); 

     // Assign routed segments, index starting from 1 
     $this->uri->rsegments = array(
      1 => $class, 
      2 => $method 
     ); 

     log_message('debug', 'No URI present. Default controller set.'); 
    } 
+0

私は試しましたが、 "ページが見つかりませんでした" – Vinoth

+0

私の最後にはうまく動作します。あなたのcodeigniterのバージョンを教えていただけますか? –

+0

codeigniter version 3.1.0 – Vinoth

0

添付ファイルに自分自身を見ることができるように、あなたはルートを設定していません。これを行うには、 "application> config> routes.php"でルートパスを設定します。

+0

私はそれを試しましたが動作しません。 – Vinoth

+1

codeigniter user_guideを実行してください:https://www.codeigniter.com/userguide3/general/routing.html – varun

関連する問題