如何获得CodeIgniter 2.1.4加载扩展的控制器类? [英] How can I get CodeIgniter 2.1.4 to load my extended Controller Class?

查看:46
本文介绍了如何获得CodeIgniter 2.1.4加载扩展的控制器类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在通过stackoverflow寻找此答案,但没有一个能够帮助我。

I have looked for this answer all through stackoverflow and none have been able to help me.

我的文件名是:application / core / MY_Controller.php

my file name is: application/core/MY_Controller.php

class MY_Controller extends CI_Controller {

/**
 * Constructor
 */
public function __construct()
{
        parent::__construct();

}

}

我做了一个在此线程中发帖询问是否有人找到了答案。我尝试了该线程中的所有内容,并尝试了所有建议的链接。

I made a post in this thread asking if anyone had found an answer. I tried everything in that thread, and in all suggested links.

我完全不知所措。

一切都可以在我的本地WAMP服务器(apache 2.4 php 5.4)上运行,而不能在生产服务器(ubuntu 12.04,apache 2.4,php 5.5)上运行

Everything works on my local WAMP server (apache 2.4 php 5.4) and not on the production server (Ubuntu 12.04, apache 2.4, php 5.5)

错误:


PHP致命错误:在第7行的filepath / application / controllers / welcome.php中找不到类'MY_Controller'。

PHP Fatal error: Class 'MY_Controller' not found in filepath/application/controllers/welcome.php on line 7.

第7行是我定义类的地方: class welcome扩展MY_Controller {

Line 7 is where I define the class: class welcome extends MY_Controller {

编辑
感谢您的所有帮助。我弄清楚出了什么问题。
最初尝试解决此问题时,我注意到我的MY_Controller.php名称不正确,就是My_Controller.php。

EDIT Thanks for all the help. I figured out what was wrong. When I initially started trying to figure out this problem, I noticed that I did not have my case right on the name of MY_Controller.php, it was My_Controller.php.

因此,我发现即使我在本地计算机上更改了文件名,但在上传文件时,名称仍然没有变化。因此,当我将其全部更改为小写字母时,我决定直接在生产服务器上执行此操作,并发现在所有这些时间之后,当我以为自己更改了该名称时,仍然使用小写字母y命名。我希望这可以帮助从WAMP环境迁移到LAMP环境的其他人知道,即使大小写发生了变化,它仍然是相同的名称,并且在上载时可能会更改,也可能不会更改。

So, what I found out was that even though I changed the name of the file on my local machine, when I uploaded it, the name still didn't change. So, when I went to change it to all lower case I decided to do that directly on the production server and found that after all this time it was still named with the lowercase y when I thought I had changed that. I hope this helps anyone else who migrates from a WAMP environment to a LAMP environment to know that even though the case is changed, it is still the same name, and may or may not be changed when you upload it.

推荐答案

请转到您的 application / config / config.php 并在底部插入此代码代码

please go to your application/config/config.php and on the bottom insert this code

function __autoload($class)
{
 if(strpos($class, 'CI_') !== 0)
 {
  @include_once( APPPATH . 'core/'. $class . EXT );
 }
}

现在,您很好。

请尝试在/ core文件夹中使用此主体创建文件MY_Controller.php

please try creating file MY_Controller.php in /core folder with this body

class MY_Controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->output->enable_profiler(TRUE);
    }

}

,如果可以使用欢迎控制器

and use welcome controller if it works.

我错过了笔记:一切都在我的本地WAMP服务器(Apache 2.4 php 5.4)上运行,而不在生产服务器上运行(Ubuntu 12.04,Apache 2.4,PHP 5.5)

I missed note: Everything works on my local WAMP server (apache 2.4 php 5.4) and not on the production server (Ubuntu 12.04, apache 2.4, php 5.5)

请检查您的文件/控制器情况

请尝试对所有内容进行小写/重命名(即使 my_controller扩展了CI_Controller )。

Please try editing/renaming everything in to lower case (even my_controller extends CI_Controller).

这篇关于如何获得CodeIgniter 2.1.4加载扩展的控制器类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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