2016-03-24 10 views
0

私はCodeigniter 3.0を使用しています。私はそれがサブフォルダー内のファイルにルーティングすることができないことがわかった。 このガイドのようにsystem/coreのroute.phpファイルを編集した後: default controller inside subfolder codeigniter 3 not working ページが正しくルーティングされます。 しかし、私はそのようなアップロードホストの後にエラーが表示されます。 "要求されたファイルをロードすることができません:フロントエンド/ Home.phpを" 私の構造:Codeigniter 3.0 - 要求されたファイルを読み込めません:サブフォルダ/ file.php

-controllers 
    -frontend 
    Home.php 
-views 
    - frontend 
    Home.php 

マイルートファイル:

$route['default_controller'] = 'frontend/Home'; 

クラスの名前を確認しました。最初の文字は大文字です。

+0

"要求されたファイルを読み込めません"というのは、*表示*していないようです。コントローラーであれば、404エラーメッセージになります。ビューのロードが '$ this-> load-> view(" frontend/home ");' – MackieeE

答えて

0

CodeIgniterはhomeの方法でコントローラFrontendを探します。あなたは2つの方法でそれを解決することができます。次のコードでcontrollersディレクトリにHome.phpコントローラを作るための最初のIW:

<?php 

/* 
* Custom router function v 0.1 
* 
* Add functionality : read into more than one sub-folder 
* 
*/ 

class MY_Router extends CI_Router 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
    } 

    public function _validate_request($segments) 
    { 
     if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) 
     { 
      return $segments; 
     } 

     if (is_dir(APPPATH.'controllers/'.$segments[0])) 
     { 
      $this->set_directory($segments[0]); 
      $segments = array_slice($segments, 1); 

      /* ----------- ADDED CODE ------------ */ 

      while(count($segments) > 0 && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0])) 
      { 
       // Set the directory and remove it from the segment array 
       $this->set_directory($this->directory . $segments[0]); 
      $segments = array_slice($segments, 1); 
      } 

      /* ----------- END ------------ */ 

      if (count($segments) > 0) 
      { 
       if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) 
       { 
        show_404($this->fetch_directory().$segments[0]); 
       } 
      } 
      else 
      { 
       $this->set_class($this->default_controller); 
       $this->set_method('index'); 

       if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) 
       { 
        $this->directory = ''; 
        return array(); 
       } 

      } 

      return $segments; 
     } 

     show_404($segments[0]); 
    } 
} 

CreditsAPPPATH.'config/routes.php'コード

$route['default_controller'] = 'home'; 

第二の方法で

<?php defined('BASEPATH') OR exit('Restricted area!'); 

class Frontend extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
    } 

    public function index() 
    { 
     $this->home(); 
    } 

    public function home() 
    { 
     redirect('frontend/home', 'refresh'); 
    } 
} 

は、カスタムメイドのルータのクラスを使用することです。

+0

あなたの返信に感謝します!私の問題はホスト上でルーティングすることができません。私はチェックしたがまだ動作していない。 –

+0

私は答えを編集しました、この方法で試してください(最初の解決策)。 – Tpojka

+0

ここに何か間違っています。 $ルート['default_controller'] = 'ホーム'; => CIは、frontendサブフォルダ Btwのhome.phpがリダイレクトされていないため、コントローラフォルダ内にhome.phpクラスが見つかります(Dはありません)。 –

関連する問題