Url
Your URLs should usually contain all lowercase letters. If you expect uppercase letters, you can accidentally exclude their subordinate copies, although they have the same URL. Example: www.example.com/controller/method/param
Controllers
Controller class names must be lowercase than the first letter.
- If your URL is
www.example.com/gallery , the controller name is Gallery . - If your URL is
www.example.com/admin_folder , the name of the controller is Admin_folder .
The controller file names must match the class name, but all lowercase letters.
- Gallery ::
gallery.php - Admin_folder ::
admin_folder.php
Controller methods must also be lowercase. There is some flexibility with uppercase letters, but similar to URLs, there are possibilities in which this can happen ( here is an example where the uppercase letters interfered with the form validation callback method).
Models
Models comply with most of the same conventions as controllers. The only difference is the names of the model methods that may use your preference for capitalization. Since these methods are not bound to URLs and are called using regular PHP OOP, you can name them whatever you want.
It is recommended that you download models using the entire line version. Although CI is not required, it can confuse some users if they load it with a capital letter, but then try to access it like all lowercase (this is because native PHP is case sensitive with class properties [and variables in general], and not CodeIgniter).
- Model class name:
Users_model (the suffix _model also not required, but some people may use it as a personal preference or prevent name conflicts with the Users controller). - Model File Name:
users_model.php - Model loading:
$this->load->model('users_model') - Model method name (everything is fine):
$this->users->getAll() , $this->users->find_by_name($name) , etc.
Libraries
Libraries follow the same conventions except for the file name. In this case, the file names must match the class name.
As with models, it is recommended that you load libraries using lowercase names.
These rules are the same for CI libraries (located in application/core and application/libraries ), as well as custom or third-party libraries.
Special note: when extending CI libraries by default, the prefix, as defined in application/config.php , comes into play. Usually this prefix should be uppercase and then underline. The default is MY_ .
- Library Class Name:
Photos - Library File Name:
Photos.php , - Library loading:
$this->load->library('photos')
Assistants
The names and loading helpers are lowercase letters. The file name consists of the helper name with _helper added after.
- Helper Name:
url - Helper File Name:
url_helper.php - Auxiliary load:
$this->load->helper('url')
Notes
CodeIgniter is somewhat inconsistent in its naming conventions, but there really aren't many rules, so it's easy to get used to and remember. I rarely have problems with naming and loading in CI, and when I do this, it's usually because I just worked on a project related to the composer, so I got a different habit.
The rules in this answer are for CodeIgniter 2.1.x at the time of this writing. Github is discussed from 3.0 to better and adds more consistency to naming conventions that you can read about and contribute if you want.