Welcome Guest, Not a member yet? Register   Sign In
Logic behind CI naming conventions...
#1

[eluser]Unknown[/eluser]
Can someone politely explain to me the logic behind CI's naming conventions, specifically regarding the controllers and models. For example, logic dictates that all the classes begin with an upper case letter, yet you want the files to be lower case.

While I am not new to programming, this naming convention is new to me.

To be honest, and maybe I just don't get it, but this doesn't make sense to me, and it is rather annoying. This is especially true when I like to name all classes, files, models, views, and controllers the same.

This isn't meant to be a troll, I'd honestly like to know why the designers thought this was a wonderful idea.

Kind regards,
claytonjr

EDIT: If anyone knows a simple hack to turn this off, I'd sincerely appreciate it.
#2

[eluser]WanWizard[/eluser]
I'm pretty sure there's no logic behind it, just developer preference.

Classes are loaded by the Loader class, in _ci_load_class(). It does:
Code:
// We'll test for both lowercase and capitalized versions of the file name
foreach (array(ucfirst($class), strtolower($class)) as $class)
so for files it checks both ucfirst and lowercase.

Given the fact that it checks ucfirst first, and all files in the core are ucfirst too, I would say that the naming convention is ucfirst for both filename and classname.
#3

[eluser]Unknown[/eluser]
Thanks for the quick reply. Can you or anyone recommend some good tips, or best practices concerning file/controller/view/model/class naming?
#4

[eluser]WanWizard[/eluser]
I can't find anything related to the correct file conventions, but the code suggests they should be ucfirst(). The documentation however is inconclusive, as it mentions lowercase files in different places.

For the rest, the Style Guide is pretty specific.
#5

[eluser]Aken[/eluser]
Class names should always be ucfirst-style; no other capital letter should exist except the first letter.

Filenames should either match the class name, or be all lowercase. Sometimes lowercase can make your life easier depending on the case sensitivity on your server.

Remember that this is not just specifically related to filenames - the Loader class uses he same guides when you use $this->load->library() or similar. That's what allows users to load a library in all lowercase.

It's not the best solution, and I doubt you'll find a thought-out explanation for it from an original developer (it's been like this for a long time).




Theme © iAndrew 2016 - Forum software by © MyBB