dtf579777 2017-04-17 20:46
浏览 19
已采纳

在Codeigniter 2.0中扩展控制器

I would like to ask, if what is the proper way of extending a controller in codeigniter. Because right now I am encountering a Fatal error: Class 'ApiController' not found in both files resides on the same directory api folder. Here's my code:

<?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(){

    }
}

展开全部

  • 写回答

4条回答 默认 最新

  • duanhuihui2705 2017-04-18 04:14
    关注

    You need to include the Base Class file before extending it .

    <?php
    //EchelonApiController.php
    
    require "path/to/file/ApiController.php";
    
    class EchelonApiController extends ApiController {
    
        public function __construct() {
           parent::__construct();
        }
    
        public function index(){
           echo 'asd';
        }
    }
    

    if ApiController.php and EchelonApiController.php both are in same file , you can directly use

    require "ApiController.php";
    

    otherwise just add correct path with the help of APPPATH constant.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部