Chapter 3: A 10,000 - Foot View of CodeIgniter
68
Controllers
For simplicity ’ s sake, you ’ re going to use the default controller, welcome.php, for the first part of this
project. As things progress, you can create additional controllers as needed.When you look at your project notes, you know that the following main destinations are required by
your application:A home pageA Category page, showing subcategoriesA subcategory page, showing productsA Product Detail pageA Shopping Cart pageA Search Results pageVarious other minor pages, such as Contact Us, About Us, and Privacy PolicyEach of these destinations becomes a function of your controller. If you want users to visit an about_us
page on your site, you need an about_us function in your controller. Right now you don ’ t care about the
details of what happens at those destinations; you just want to sketch them in, without regard to loading
models, views, helpers, or anything else.Your primary goal right now is to get an overview of the project space, so you open the default welcome
.php controller in /system/application/controllers/ and get to work:class Welcome extends Controller {
function Welcome(){
parent::Controller();
}function index(){
//use this for your home page
}function cat(){
//use this for the category page
}function subcat(){
//use this for the subcategory view
}function product(){
//use this for the product view
}function cart(){
//use this for the shopping cart view
}