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

标签 php linux codeigniter

我遇到了一个区分大小写的问题,但我无法解决这个问题。

这就是我的文件结构。我只输入了我正在使用的目录,但实际上我使用的是 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();
    }
}

/application/core/Public_Controller.php

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

    // Application logic here...
}

/application/controllers/application_controller.php

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

感谢您的任何建议!

最佳答案

代码点火器 change log

Changed filenaming convention (class file names now must be Ucfirst and everything else in lowercase).

所以你的 Controller 和文件名应该是

  • My_controller(只有 M 大写其余小写)
  • 公共(public)控制者
  • 应用程序 Controller
  • Foo_controller

我自己不喜欢新的命名约定 CI-2 在这种情况下更好。

注意:

Controller 名称 Public_Controller(C 大写)和文件名称 Public_controller.php 可能有效,但我更喜欢保持两个名称相同,因此 Controller 名称应为 Public_controller.

关于php - Linux (centos) 上的 Codeigniter 类和文件名区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31145215/

相关文章:

linux - 未找到 yocto defconfig

mysql - 如何在 CodeIgniter 模型中使用 ON DUPLICATE KEY UPDATE?

css - 提交表单时图像消失

php - 使用 count 从两个表中选择总行数

PHP 从一种表单更新数据库上的不同字段

regex - 使用正则表达式重命名文件 - Linux

regex - 如何获取第二列和第二行中的数字或返回默认值

mysql - 我需要选择条件这个

php - 选择查询时格式化日期列

php - faker 库和准备好的语句无法正常工作且没有错误显示