Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Linux(centos)上的Codeigniter类和文件名区分大小写_Php_Linux_Codeigniter - Fatal编程技术网

Php Linux(centos)上的Codeigniter类和文件名区分大小写

Php Linux(centos)上的Codeigniter类和文件名区分大小写,php,linux,codeigniter,Php,Linux,Codeigniter,我遇到了一个区分大小写的问题,我无法集中精力解决它 这就是我的文件结构。我只输入我正在使用的目录,但实际上我使用的是完整安装的CI3 /application .... /controllers/ application_controller.php /core/ MY_Controller.php Public_controller.php .... /models/ Application

我遇到了一个区分大小写的问题,我无法集中精力解决它

这就是我的文件结构。我只输入我正在使用的目录,但实际上我使用的是完整安装的CI3

/application
    ....
    /controllers/
        application_controller.php
    /core/
        MY_Controller.php
        Public_controller.php
    ....
    /models/
        Application_model.php
    ....
下面是类定义语法的样子:

/application/core/My_Controller.php

class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }
}
class Public_Controller extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    // Application logic here...
}
class Application_controller extends Public_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    // Application logic here...
}
/application/core/Public\u Controller.php

class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }
}
class Public_Controller extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    // Application logic here...
}
class Application_controller extends Public_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    // Application logic here...
}
/application/controllers/application\u controller.php

class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }
}
class Public_Controller extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    // Application logic here...
}
class Application_controller extends Public_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    // Application logic here...
}
阅读文档后,我发现我应该给我的类命名如下:

Foo_Controller.php
然后我一直认为类定义应该与文件名匹配。因此:

class Foo_Controller extends Bar_Controller {
    ....
}
然后我要么得到一个500错误,要么没有错误,还有一个白色页面。 当我在本地(mac)工作时,一切都很好。现在(使用上面的语法),我至少得到了默认的codeigniter 404页面。使用时

error_log(__FILE__); 
在每堂课的顶端,我要做的就是
My_Controller.php


谢谢你的建议

正如@jagad89所说,
application\u controller.php
的文件名应该是 “…必须以类似Ucfirst的方式命名,或者换句话说,它们必须以大写字母开头。”因此
Application\u controller.php

这意味着您的所有控制器、模型、库和驱动程序(非帮助程序)必须以这种方式命名,才能在codeigniter内部使用

为了统一起见,您的类定义应该与您所说的文件名匹配

您应该在日志中看到500个错误,至少在linux上,位于
/var/log/apache2/error.log
,这将有助于调试过程

代码点火器说

更改了文件命名约定(类文件名现在必须是Ucfirst所有其他小写文件名

所以你的控制器和文件名应该是

  • My_控制器(仅M大写剩余小写)
  • 公共无线电控制器
  • 应用程序控制器
  • Foo_控制器
我自己也不喜欢新的命名约定CI-2在这种情况下更好

注意:

控制器名
Public\u Controller
(大写C)和文件名
Public\u Controller.php
可能可以工作,但我更喜欢保持两个名称相同,因此控制器名应该是
Public\u Controller

我的解决方案 在/application/core/i中创建一个MY_Loader.php(MY_L的大写字母)
我用原始函数“model”的副本创建了一个类MY_Loader
我对行“$model=ucfirst($model);”

/application/core/MY_Loader.php的代码:

class MY_Loader extends CI_Loader { /*this a copy of function model of the class CI_Loader from /system/core/Moader.php */ public function model($model, $name = '', $db_conn = FALSE) { if (empty($model)) { return $this; } elseif (is_array($model)) { foreach ($model as $key => $value) { is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn); } return $this; } $path = ''; // Is the model in a sub-folder? If so, parse out the filename and path. if (($last_slash = strrpos($model, '/')) !== FALSE) { // The path is in front of the last slash $path = substr($model, 0, ++$last_slash); // And the model name behind it $model = substr($model, $last_slash); } if (empty($name)) { $name = $model; } if (in_array($name, $this->_ci_models, TRUE)) { return $this; } $CI =& get_instance(); if (isset($CI->$name)) { throw new RuntimeException('The model name you are loading is the name of a resource that is already being used: '.$name); } if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE)) { if ($db_conn === TRUE) { $db_conn = ''; } $this->database($db_conn, FALSE, TRUE); } // Note: All of the code under this condition used to be just: // // load_class('Model', 'core'); // // However, load_class() instantiates classes // to cache them for later use and that prevents // MY_Model from being an abstract class and is // sub-optimal otherwise anyway. if ( ! class_exists('CI_Model', FALSE)) { $app_path = APPPATH.'core'.DIRECTORY_SEPARATOR; if (file_exists($app_path.'Model.php')) { require_once($app_path.'Model.php'); if ( ! class_exists('CI_Model', FALSE)) { throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model"); } } elseif ( ! class_exists('CI_Model', FALSE)) { require_once(BASEPATH.'core'.DIRECTORY_SEPARATOR.'Model.php'); } $class = config_item('subclass_prefix').'Model'; if (file_exists($app_path.$class.'.php')) { require_once($app_path.$class.'.php'); if ( ! class_exists($class, FALSE)) { throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class); } } } //~ $model = ucfirst($model);/*this the line that i comment*/ if ( ! class_exists($model, FALSE)) { foreach ($this->_ci_model_paths as $mod_path) { if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) { continue; } require_once($mod_path.'models/'.$path.$model.'.php'); if ( ! class_exists($model, FALSE)) { throw new RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model); } break; } if ( ! class_exists($model, FALSE)) { throw new RuntimeException('Unable to locate the model you have specified: '.$model); } } elseif ( ! is_subclass_of($model, 'CI_Model')) { throw new RuntimeException("Class ".$model." already exists and doesn't extend CI_Model"); } $this->_ci_models[] = $name; $CI->$name = new $model(); return $this; } } 类MY_Loader扩展CI_Loader { /*这是/system/core/Moader.php中类CI_Loader的函数模型的副本*/ 公共函数模型($model,$name='',$db_conn=FALSE) { if(空($model)) { 退还$this; } elseif(is_阵列($model)) { foreach($key=>$value的模型) { is_int($key)?$this->model($value,,$db_conn):$this->model($key,$value,$db_conn); } 退还$this; } $path=''; //模型是否在子文件夹中?如果是,请解析出文件名和路径。 if($last_slash=strrpos($model,'/'))!==FALSE) { //路径位于最后一条斜线的前面 $path=substr($model,0,+$last_斜杠); //以及它背后的型号名称 $model=substr($model,$last_斜杠); } if(空($name)) { $name=$model; } if(在数组中($name,$this->\u ci\u models,TRUE)) { 退还$this; } $CI=&get_instance(); if(isset($CI->$name)) { 抛出新的RuntimeException('正在加载的模型名称是已在使用的资源的名称:'。$name); } 如果($db_conn!==FALSE&!class_存在('CI_db',FALSE)) { 如果($db_conn===TRUE) { $db_conn=''; } $this->database($db_conn,FALSE,TRUE); } //注:此条件下的所有代码过去仅为: // //荷载等级(“模型”、“核心”); // //但是,load_class()会实例化类 //以缓存它们以供以后使用,从而防止 //我的_模型不再是一个抽象类,而是 //次优,否则无论如何。 如果(!class_存在('CI_Model',FALSE)) { $app_path=APPPATH'core'。目录_分隔符; 如果(文件_存在($app_path.Model.php')) { 需要一次_($app_path.Model.php'); 如果(!class_存在('CI_Model',FALSE)) { 抛出新的RuntimeException($app_path。“Model.php存在,但未声明类CI_Model”); } } elseif(!class_exists('CI_Model',FALSE)) { 需要_一次(BASEPATH.core.DIRECTORY_SEPARATOR.Model.php'); } $class=config_项('subclass_前缀')。'Model'; 如果(文件_存在($app_path.$class.'.php')) { 需要一次($app_path.$class.'.php'); 如果(!class_存在($class,FALSE)) { 抛出新的RuntimeException($app_path.$class..php存在,但未声明类“..$class”); } } } /~$model=ucfirst($model);/*这是我评论的行*/ 如果(!class_存在($model,FALSE)) { foreach($this->\u ci\u model\u路径为$mod\u路径) { 如果(!file_存在($mod_path..models/'.$path.$model..php'))