我尝试在codeigniter中创建core类,在application/core中创建一个名为MY_head. php的文件,MY_head. php的代码是:
class MY_head extends CI_Controller{
public function __construct(){
parent::__construct();
}
public function load_header(){
//some code here
}
}
现在我尝试在我的控制器practice.php中扩展这个类,代码是:
class Practice extends MY_head{
public function __construct(){
parent::__construct();
}
function index(){
}
}
但当我在浏览器中加载练习控制器时,它显示
致命错误:在中未找到类“MY_head”。
问题出在哪里?
注意:$config ['子类前缀']= 'MY_';
3条答案
按热度按时间u0njafvf1#
function __autoload($class)
已弃用:PHP 7.x及更高版本的更新
ulmd4ohb2#
尝试将以下函数放在配置文件的底部
/应用程序/配置文件/配置文件php
和扩展控制器
或手动包括
chy5wohz3#
你可能不想手动包含它或者在每次创建核心类的时候修改CI系统。你只需要改变类名的大小写,CI就可以读取它。例如
MY_Head
或者MY_Head_Controller
。这些是类名的格式。所以你的核心类名应该是并称之为
我试过了,很管用。
**注意。**如果您的类前缀是
MY_
并且您扩展了CI_Controller
,则文件名必须是MY_Controller.php
。