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

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

问题描述



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

我通过stackoverflow找到了这个答案,没有一个能帮助我。 p>

  class MY_Controller extends CI_Controller {

/ **
*构造函数
*
public function __construct()
{
parent :: __ construct();

}

}

在此主题中发帖,询问是否有人找到答案。



我完全失去了。



一切都在我的本地WAMP服务器上工作(apache 2.4 php 5.4),而不是在生产服务器上(Ubuntu 12.04,apache 2.4,php 5.5)



错误:

  PHP致命错误:在文件路径/ application / controllers / welcome.php中没有找到类'MY_Controller'。

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



EDIT
感谢您的帮助。我想出了什么是错的。
当我最初开始试图找出这个问题,我注意到我没有我的情况下MY_Controller.php的名称,它是My_Controller.php。



所以,我发现,即使我更改了本地机器上的文件名,当我上传时,该名称仍然没有改变。所以,当我去改变它所有的小写,我决定直接在生产服务器上这样做,发现,所有这一次后,它仍然命名为小写y,当我以为我改变了。我希望这可以帮助任何人从WAMP环境迁移到LAMP环境,知道即使情况被改变,它仍然是同一个名字,并且可能或不会改变,当你上传它。

解决方案

请转到您的 application / config / config.php 代码

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






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

  class MY_Controller extends CI_Controller {

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

}

并使用欢迎控制器。






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



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



请尝试将所有内容编辑/重命名为小写(甚至 my_controller扩展CI_Controller )。


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

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.

I'm at a complete loss.

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)

error:

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

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

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.

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.

解决方案

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 );
 }
}

Now you are good to go.


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.


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)

Please check your case of files/controllers

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

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

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