Linux (centos) 上的 Codeigniter 类和文件名区分大小写 [英] Codeigniter Class and filename case sensitive on Linux (centos)

查看:25
本文介绍了Linux (centos) 上的 Codeigniter 类和文件名区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个区分大小写的问题,我无法理解它的出现.

I am running into a case-sensitive problem that I'm not able to wrap my head around it appears.

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

This is what my file structure looks like. I am only entering the directories that I am working with, but I am in fact using a full-install of 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...
}

阅读文档,我发现我应该将类命名为:

Reading the docs, I see that I should name my classes something like:

Foo_Controller.php

然后我一直(认为)类定义应该与文件名匹配.所以:

Then i've always (thought) that the class definition should match the file name. So:

class Foo_Controller extends Bar_Controller {
    ....
}

然后我要么收到 500 错误,要么没有收到错误,并且出现一个白页.当我在本地 (mac) 工作时,一切正常.到目前为止(使用上面的语法)我至少得到了默认的 codeigniter 404 页面.使用时

Then I either get a 500 error, or I get no errors, and a white page. When I work locally (mac) everything works perfectly. As of right now (using the syntax above) I am at least getting the default codeigniter 404 page. When use

error_log(__FILE__); 

在每个类的顶部,我所得到的只是My_Controller.php

at the top of each class, all I am getting to is My_Controller.php

感谢您的任何建议!

推荐答案

Codeigniter 更改日志

Codeigniter change log says

更改了文件命名约定(类文件名现在必须Ucfirst 并且其他所有内容都必须小写).

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

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

So you controllers and files name should be

  • My_controller(仅 M 大写其余小写)
  • 公共控制器
  • Application_controller
  • Foo_controller

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

I myself don't like new naming convention CI-2 was better in this case.

注意:

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

Controller name Public_Controller(C uppercase) and file name Public_controller.php may work but I prefer to keep both name same so controller name should be Public_controller.

这篇关于Linux (centos) 上的 Codeigniter 类和文件名区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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