codeigniter MY_Controller not found(找不到代码点火器 MY_Controller)
问题描述
我在网站上使用 Codeigniter.2.1.3,所以我需要扩展 CI_Controller 以便我可以添加一个要与所有控制器一起执行的方法,所以我做了 user_guide 中的内容:
i’m using the Codeigniter.2.1.3 for a website, so i need to extend the CI_Controller so i can add a method to be executed with all controllers so i did what’s in the user_guide:
在 application/core 文件夹中创建一个名为 MY_Controller.php 的文件,在其中创建扩展 CI_Controller 的 MY_Controller 类,更改我的常规控制器以扩展 MY_controller,如下所示:MY_controller.php:
creating a file named MY_Controller.php in the application/core folder the creating in it MY_Controller Class that extends the CI_Controller, the changing my regular controller to extend the MY_controller like this: MY_controller.php:
class MY_Controller extends CI_Controller{
protected $page;
# Constructor
function __construct (){
parent::__construct();
#code shared with all controllers
}
public function get_page(){
#code to get_the right page here
}
}
名为 Regular.php 的常规控制器:
regular controller named Regular.php:
class Regular extends MY_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->get_page();
}
}
但不断出现以下错误:
致命错误:在第 2 行的/var/www/immo/CodeIgniter_2.1.3/application/controllers/regular.php 中找不到MY_Controller"类
Fatal error: Class ‘MY_Controller’ not found in /var/www/immo/CodeIgniter_2.1.3/application/controllers/regular.php on line 2
推荐答案
您需要包含您的 MY_Controller 类或自动加载它.我建议您通过将以下内容添加到您的 application/config/config.php 文件来自动加载它.
You would need to include your MY_Controller class or auto-load it. I suggest you auto-load it by adding the following to your application/config/config.php file.
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/' . $class . EXT))
{
include $file;
}
}
}
这篇关于找不到代码点火器 MY_Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找不到代码点火器 MY_Controller
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
