标签:
这两天看了下CI3,想使用controller继承,后来才发现CI的继承是另有玄机,这里做个笔记。
1、检查application\config\config.php文件
$config[‘subclass_prefix‘] = ‘MY_‘;
值为My_,那么你的controller需要以这个开头
2、在application\core文件夹下面新建My_Controller.php文件
<?php
defined(‘BASEPATH‘) OR exit(‘No direct script access allowed‘);
/**
*My_Controller
**/
class My_Controller extends CI_Controller{
public function __construct(){
parent::__construct();
}
}
?>
3、在你的controllers中使用它
<?php
defined(‘BASEPATH‘) OR exit(‘No direct script access allowed‘);
class User extends My_Controller{
public function __construct(){
parent::__construct();
$this->load->library(‘theme‘);
}
}
?>
标签:
原文地址:http://my.oschina.net/kenblog/blog/411701