Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Class File Naming Conventions
#1

[eluser]matthewwithanm[/eluser]
A recent problem with Modular Extensions (HMVC) sent me back to the CodeIgniter user guide to figure out the conventions for naming a class file. I was really surprised to see that they specify different things for different types of class!

According to the Class and Method Naming section, all classes names should have words separated by underscores and only the first letter capitalized. For example: My_awesome_class. (This is contradicted by the examples of "Someclass" and "Myclass" in the Creating Libraries section, but I think that's just a mistake.)

However, this section doesn't specify what the file should be named, and you have to do some digging to find out:

Anatomy of a Model explicitly states that the file name should be "a lower case version of your class name." So, "my_awesome_class.php".

According to Creating Libraries, "class names and file names must match." This seems to imply the filename would be "My_awesome_class.php". This is backed up by the core library classes which are all in this format.

The Controllers section isn't explicit, but its examples use the same convention as the Models: all lowercase.

Does anybody know the reasoning behind these confusing discrepancies? Why don't class names have a consistent mapping to file names?

Thanks.
#2

[eluser]gyo[/eluser]
Actually it make sense, as the only Capitalized files are the libraries, which might be seen as the "real" classes (which generally have Capital letters).

Of course, nothing forces you to get rid of your own style: for example I use Capitalized models when they belong to a database table (for ORM like operations).
#3

[eluser]Sepehr Lajevardi[/eluser]
It's still confusing Smile
#4

[eluser]InsiteFX[/eluser]
What's confusing about it?

Libraries file name first letter Capitalized.

All others Lowercase.
#5

[eluser]Sepehr Lajevardi[/eluser]
yeah, I know, I mean in the documentation.




Theme © iAndrew 2016 - Forum software by © MyBB