2017-04-18 4 views
0

codeigniterでコントローラを拡張する適切な方法は何かをお聞きしたいと思います。現在、私はFatal error: Class 'ApiController' not found inの両方のファイルが同じディレクトリapiフォルダに存在するため、遭遇しています。私のコードは以下の通りです:Codeigniter 2.0でコントローラを拡張する

<?php 
//EchelonApiController.php 
class EchelonApiController extends ApiController { 

    public function __construct() { 
     parent::__construct(); 
    } 

    public function index(){ 
     echo 'asd'; 
    } 
} 


<?php 
// ApiController.php 
class ApiController extends CI_Controller { 

    public $table; 

    public function __construct(){ 

     parent::__construct(); 

     $this->load->models("api/".$table); 
    } 

    public function index(){ 

    } 
} 

答えて

1

拡張する前に、基本クラスファイルを含める必要があります。

<?php 
//EchelonApiController.php 

require "path/to/file/ApiController.php"; 

class EchelonApiController extends ApiController { 

    public function __construct() { 
     parent::__construct(); 
    } 

    public function index(){ 
     echo 'asd'; 
    } 
} 

ApiController.phpEchelonApiController.phpの両方が同じファイル内にある場合は、直接、そうでない場合は、単にAPPPATH定数の助けを借りて、正しいパスを追加

require "ApiController.php"; 

を使用することができます。

0

アプリケーション/コアディレクトリにApiControllerを配置します。

関連する問題