问题
当我尝试拨打http://my_url/api/login/gethomescreen
时,它给了我错误Fatal error: Class 'MY_API_Controller' not found
当我添加Login.php
require APPPATH . '/core/MY_API_Controller.php';
的后续行顶部时,它工作正常
当我在config.php中添加__autoload()
并加载CI_Controller
但是根据codeigniter结构,它应该在没有包含文件的情况下工作。父类应该在我扩展时自动加载。我只是想知道为什么会发生这种情况? 这是我的代码和路径详细信息 Login.php
class Login extends MY_API_Controller {
public function __construct() {
parent::__construct();
}
public function gethomescreen_post(){
//my code goes here
}
}
MY_API_Controller.php
ob_clean();
require APPPATH . '/libraries/REST_Controller.php';
class MY_API_Controller extends REST_Controller {
protected $_options = array();
public function __construct() {
parent::__construct();
// Load the jwt.php configuration file
if (empty($options)) {
$this->load->config('jwt', true);
$options = $this->config->item('jwt');
}
$this->_options = $options;
$this->load->model('users_model');
}
}
REST_Controller.php
abstract class REST_Controller extends CI_Controller {
public function __construct($config = 'rest') {
parent::__construct();
$this->preflight_checks();
//further code....
}
}
文件路径
application\controllers\api\Login.php
application\libraries\REST_Controller.php
application\core\MY_API_Controller.php
答案 0 :(得分:0)
在config文件夹的config.php文件中,此行已设置:
$config['subclass_prefix'] = 'MY_';
为:
$config['subclass_prefix'] = 'MY_API_';