Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 3.0 forced uppercase naming of controllers and classes
#1

(This post was last modified: 05-18-2016, 08:54 AM by stefano.corsi.)

Dear All,

I have quite a lot of projects based on Codeigniter 2.1.

I'm considering porting them all to Codeigniter 3 and also consolidating Codeigniter 3 as my standard development platform.

One thing is blocking me, both practically and conceptually: the forced uppercase file naming of the controllers and classes.

First of all because I should change filename to many of my established controllers and libraries and I wouldn't like to do that.

Secondly, because having mixed case file names creates incongruence when developing on Windows (things that work on Windows but do not work on Unix in production) and these incongruences ater often difficult to discover.

Is there a way to configure or very simply patch Codeigniter to behave like before, allowing lowercase controller and class file names?

Thank you.

Stefano
Reply
#2

(05-18-2016, 02:51 AM)stefano.corsi Wrote: Secondly, because having mixed case file names creates incongruence when developing on Windows (things that work on Windows but do not work on Unix in production) and these incongruences are often difficult to discover.

And that is one of the reasons that a file naming requirement exists in the first place. This ensures that you can't name the file is always in the casing it's expected to be an will function perfectly in both case-sensitive and case-insensitive filesystems. Previously, the system checked for both versions of the file name and file searches aren't the most inexpensive process so this aids performance, also.

Quote:Is there a way to configure or very simply patch CodeIgniter to behave like before, allowing lowercase controller and class file names?

While I'm sure there's way you could patch it, it's not recommended. You could create a small script that would change the filenames for you instead of having to do it manually.

While we all understand it's not a fun thing to do, it's not likely to change now.
Reply
#3

(05-18-2016, 09:43 AM)kilishan Wrote:
(05-18-2016, 02:51 AM)stefano.corsi Wrote: Secondly, because having mixed case file names creates incongruence when developing on Windows (things that work on Windows but do not work on Unix in production) and these incongruences are often difficult to discover.

And that is one of the reasons that a file naming requirement exists in the first place. This ensures that you can't name the file is always in the casing it's expected to be an will function perfectly in both case-sensitive and case-insensitive filesystems. Previously, the system checked for both versions of the file name and file searches aren't the most inexpensive process so this aids performance, also.

Quote:Is there a way to configure or very simply patch CodeIgniter to behave like before, allowing lowercase controller and class file names?

While I'm sure there's way you could patch it, it's not recommended. You could create a small script that would change the filenames for you instead of having to do it manually.

While we all understand it's not a fun thing to do, it's not likely to change now.

Hi Kilishan, thank you for your reply.

I disagree with this approach. Confusion is exactly what happens now... for example I ported my old files to CI 3.0 and everything worked very well on Windows (they were all rigorously lowercase as I am used to do). Deployed it in production and ... surprise... nothing worked.

I think in general developers should be free to decide if a file has to be mixed case or lowercase. I'm sure an experienced developer knows the difference and expects a framework to behave the same in both windows and unix... it's bad if CI accept lowercase files on Windows and rejects them on Unix (without any kind of informational message btw)

And also ...what I liked in the philosophy of CI was the relative simplicity and the freedom... this is for me a minor turnoff (I'm sure I'll be able to cope with it ;-) )
Reply
#4

To be fair, I wasn't the one who did the change, but I don't see a big deal either way. A major revision is a time for potential BC breaks, and it was listed in the upgrade steps rather prominently.

Quote:I think in general developers should be free to decide if a file has to be mixed case or lowercase.

Then you haven't been keeping up with the PHP community in general. Both of the autoloading PSR's require a file name to match the casing of the class name, which is forced by the other PSRs to be CamelCase. So, this isn't a unique thing to CI, and most of the other frameworks out there will force your hand in the same way.

Quote:I'm sure an experienced developer knows the difference and expects a framework to behave the same in both windows and unix... it's bad if CI accept lowercase files on Windows and rejects them on Unix (without any kind of informational message btw)

CI cannot make the operating system behave differently than it does, so it's not CI that's "allowing" lowercase names in Windows (or Mac for that matter) it's the OS. Linux, however, IS case-sensitive. And there's nothing any framework can do to change that.

While it's understandable to be frustrated, learning the differences between OSs, servers, etc, is all part of our wonderful journey from new developer to an experienced developer, unfortunately.
Reply
#5

Thank you for you answer, Kilishan, after 20 years of working in php (ahem... at the beginning it was called php-fi) plus a variety of os's I'm proud to still be a listening person and to be always ready and eager to learn, especially from brilliant people.

However, it's still a bit unclear to me what you mean. Isn't the example below showing that windows+php are able to recognise case difference?

a) I created a file "fileA" and listed the dir with a small php program:

C:\Users\aa200_000\Desktop\cartella>php test.php
Array
(
   [0] => .
   [1] => ..
   [2] => fileA.txt
   [3] => test.php
)

b) Then renamed the file "filea", all lowercase and listed the dir once again:

C:\Users\aa200_000\Desktop\cartella>php test.php
Array
(
   [0] => .
   [1] => ..
   [2] => filea.txt
   [3] => test.php
)

It seems to me that the os and the language together have a clear view of the difference... please help me understand where I'm going wrong.

Thank you
S.
Reply
#6

I'm working on a mac and there is an included utility called Automator, that will batch rename files to upper case first. There has to be something similar for Windows, so it should not take any time. I've been upgrading CI 2 projects to CI 3 and frankly I am very grateful that there are barely any breaking changes at all.
Reply
#7

Thank you Cartalot, I'm grateful as well to the community.

My post was just meant to ask if there were easy ways to revert to the old behaviour, that I personally liked more for what is my taste re file names. It's not a technical problem for me to rename files; I can use a utility, as you suggested, or simply do it by hand or write a small program. It's only a bit disturbing mentally, but that doesn't diminish my happiness for the fact that CI is still maintained.

I have nothing against Capitalisation, I can cope with it, and actually I will.
Reply
#8

(05-18-2016, 01:31 PM)stefano.corsi Wrote: It seems to me that the os and the language together have a clear view of the difference... please help me understand where I'm going wrong.

You're right, but It is not because of OS. It is because of file system.
The file system ignores the case.
Reply
#9

Hey stefano, you're correct that PHP can tell what case the file system reports the file as. But the tricky part is going the other direction.

On case-insensitive file-systems, like Windows and Mac have, if PHP tries to open "FileA" but the file is actually named "filea" there won't be a problem and you'll never notice an issue. However, as soon that site is running on Linux it will throw and error because the file system there IS case-sensitive, and "filea" !== "FileA".

In CI 2.x, IIRC, it would first look for the file as it was asked to, whether that was "FileA", "fIlEa", "filea" or whatever, If it didn't find that version of the file, it would look again for the lowercase version. That's why your scenario worked fine in previous versions. Additionally, I believe certain file types were expected to have a different capitalization than others? Don't recall for sure, but seems to tickle my memory.

In CI3 it has standardized so that all of the files are ucfirst. This keeps things consistent among the files, and keeps it working between OSs without a hitch, while allowing the framework code to be simplified, and provide a tiny performance boost at the same time. So, if you weren't used to doing it all lower case (which I will admit, I used to like better, too), then there wouldn't be any surprises when moving from one OS to another.

I don't know the exact reasons it was originally chosen to change that, but that's my best guess and understanding.
Reply
#10

@stefano.corsi
"My post was just meant to ask if there were easy ways to revert to the old behaviour ...".

There is a way, but it is not easy. I would recommend you to have a look at my application starters that I've published at GitHub, they support both the new and the old file/class naming conventions. At some moment in the future (when I migrate all my previous works) I intend to drop this BC feature for making code cleaner and faster.

At the moment I am refactoring and modernizing a 3 years old CI-based site and I realized that without supporting the old file names it would have been difficult.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB