Codeigniter扩展控制器,找不到控制器 [英] Codeigniter extending controller, controller not found

查看:202
本文介绍了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.

\ application \ core \ MY_Base_Controller.php 中,我有以下内容:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Base_Controller extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
...

\ application \ controllers \ Home.php 中,我有以下内容:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Home extends MY_Base_Controller {

错误消息是

致命错误:在第3行的... \ application \ controllers \ Home.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_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
   }
}

这篇关于Codeigniter扩展控制器,找不到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆