Codeigniter 扩展控制器,未找到控制器
在 Codeigniter 2.1.2 中,我想创建基本控制器,然后从该控制器扩展.它不起作用,我不知道为什么,我现在非常绝望.
In Codeigniter 2.1.2 I want to create base controller and then extends from this controller. It does not work and I have no idea why and I'm pretty desperate now.
在 applicationcoreMY_Base_Controller.php 我有这个:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Base_Controller extends CI_Controller
{
function __construct()
{
parent::__construct();
...
在 applicationcontrollersHome.php 我有这个:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MY_Base_Controller {
错误信息是
致命错误:在第 3 行的 ...applicationcontrollersHome.php 中找不到MY_Base_Controller"类
我不知道该怎么做,我在互联网上读到我必须将基本控制器放入核心文件夹,我必须将基本控制器命名为前缀 MY_,我做到了.但它仍然没有工作.在我的 config.php 中也是这一行
I have no idea what to do, I read all over the internet that I have to put base controller to core folder what I did, that I have to name base controller with prefix MY_, I did. But it is still no working. And in my config.php is this line as well
$config['subclass_prefix'] = 'MY_';
我使用 xampp 在本地主机上运行这个
Im running this on localhost using xampp
感谢您的帮助
编辑
有人可以下载以下链接试试看,然后告诉我出了什么问题.我刚刚下载了 codeigniter 试图创建基本控制器并扩展欢迎控制器.不工作.在下面的 rar 中只有修改过的文件.谢谢http://goo.gl/sKHkDl
Could someone please downlod following link try it, and tell me whats wrong. I have just downloaded codeigniter tried to create base controller and extend welcome controller. Not working. In following rar there are just modified files. Thank you http://goo.gl/sKHkDl
编辑 2
我可以通过将 MY_Base_Controller 重命名为 MY_Controller 来使其工作.这是否意味着,我只能为控制器创建一个扩展类?例如.我不能有
I'm able to get this working by renaming MY_Base_Controller to MY_Controller. Does this mean, I'm able to create only one extended class for a controller ? eg. I can not have
- MY_Base_Auth_Controller
- MY_Base_Article_Controller
只有MY_Controller?
推荐答案
我遇到了同样的问题,但如果我在 MY_Controller.php 文件中创建所有控制器都运行良好.
I had the same problem, but if I created all controllers in the MY_Controller.php file all worked well.
<?php
class MY_Controller extends CI_Controller
{
function __construct()
{
parent::__construct();
// do some stuff
}
}
class MY_Auth_Controller extends MY_Controller
{
function __construct()
{
parent::__construct();
// check if logged_in
}
}
相关文章