Adding products to the cart

To keep with the example, we will build a list of products, with their prices and an Add button. Now create a controller in application/controllers, call it shop.php, and for the moment, only add the following code:

<?php
class Shop extends Controller
{
function Shop()
{
parent::Controller();
}
function index()
{
$this->load->view('home');
}
}

We are only defining the class, the constructor, and creating an index method, which calls the view. This view will be the place where we build our list of products, but for now create the file in application/views/home.php, and place some simple content in it:

<h1>This is our shop home page</h1>

If we want to check that everything is working fine, we only need to go to http://localhost/codeigniterc/index.php/shop ...

Get CodeIgniter 1.7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.