dtf579777 2017-04-18 04: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 12: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条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备