Professional CodeIgniter, Thomas Myer
Chapter 3: A 10,000 - Foot View of CodeIgniter
53
The fourth
$autoload
option, model , allows you to autoload models. This is a new feature of
CodeIgniter 1.6. You are going to create two basic models for Claudia ' s Kids below, one that handles
product data and the other that handles category data. When you create those two models, you ' ll have
the opportunity to come back to this file and autoload them.
product data and the other that handles category data. When you create those two models, you ' ll have
the opportunity to come back to this file and autoload them.
Finally, the fifth
$autoload
option, config , is where you would list any custom configuration files. As it ' s
unlikely that you ' ve created any of those at this point, leave it blank.
routes.php
The routes.php file lets you remap URI requests to specific controller functions. For example, you may
have a controller named site with a function named index . The URI for this controller/function
combination might be
have a controller named site with a function named index . The URI for this controller/function
combination might be
:
http://www.example.com/site/index
Furthermore, if your site controller had a
pages
function that accepted a numeric ID for database
lookup, the URI might look like this:
http://www.example.com/site/pages/4
In some cases, you might want to remap one or more of these default routes. For example, the second
example might be better displayed as this:
http://www.example.com/about_us/
In that case, your routes.php file would contain a rule like this:
$route[`about_us'] = "site/pages/4";
For right now, though, this kind of manipulation falls under " advanced usage, " so don ' t worry too much
about it. However, please do note that this kind of thing is possible. Also, be aware that two " reserved
routes " exist: default_controller and scaffolding_trigger.
$route[`default_controller'] = "welcome";
The default_controller route tells CodeIgniter which controller should be loaded if no controller is
identified. For simplicity ' s sake, keep this setting at welcome, because you ' re going to create a welcome
controller for the project associated with this book.
CodeIgniter Libraries
CodeIgniter libraries help you do your job faster and more efficiently. Each library is really a PHP class
with various methods that you can use once the library is loaded by a controller. Some classes are so
useful and so ubiquitous that you might as well autoload them (such as the database and session
libraries).
c03.indd 53
c03.indd 53
6/10/08 5:33:48 PM
6/10/08 5:33:48 PM