Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

php - Codeigniter Class and filename case sensitive on Linux (centos)

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

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
    ....

Here is what the class definition syntax looks like:

/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 {
    ....
}

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

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

Thank you for any suggestions!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Codeigniter change log says

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 (only M upper case rest lower case)
  • Public_controller
  • Application_controller
  • Foo_controller

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

Note:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...