Tutorials

Building a basic PHP E-Commerce Application using CodeIgniter Framework – Part 3

Mar 10, 2009 insic 58 Comments

Part III – Creating the site mockup and Preparing our View.

In this part of the series we will create a design mockup for our e-commerce site. And create a reusable component of our view.

First we need to know how our site should looks like. And how we showcase our products. Basically our site should have a navigation menu, a header with a logo, a content body, a footer, and a search form.

In our homepage we need to show some of our products and put a featured product area where we can show three or more items, a main menu for our ‘home’, ‘about’, ‘contact us’ and other necessary page we need later as we go on this tutorial, and a side navigation menu for our product categories.

Take a look the site mockup I have created.

Creating the Mockup Template.

We need to create a folder where we put our files needed in making the template such as the css, images, and JavaScripts files. Now, go to the root of your CI installation then create a folder and name it as you like, in this tutorial we name it ‘public’ then inside the public folder we need to create the following folders ‘css, ‘images’, ‘js’, and ‘products’ folder for the images of our products and a ‘thumb’ folder inside our products folder for the product thumbnails.

Directory structure we have just created.

Open system/application/views folder, create a new file named it to template.php, open it in your text editor then populate the code below. Or you can go download my code here.

If you noticed there are three include files for our template first the default.css and the two javascript file, the jQuery and the s3slider.js. I am using the s3slider Plugin. We will be using this javascripts to showcase our featured products. This files are also included in the downloads.

Lets create our css file, open public/css folder and create a new file named it to default.css then populate the css code below.

Images used in stylesheet is also included in the download file. Stylesheet quite long. Coz i already included all the css styles we will be using for the entire tutorial.

For us to preview our template.php, we need to load it in our controller. Create a test controller, you can name it anything you want. For example lets create a ‘testView’ controller open system/application/controllers create a new file testview.php then populate the sample code below.

As you can see we load the url helper in this controller because if you have noticed in our template. We have this line <base href="<?= base_url(); ?>" />. This simply return the base url of our applications installation as what we set in in part 1 of this tutorial.

Now open your browser and type the url http://localhost/tutorial/testview/ . You must now see our template in action. See the online demo here.

Creating our View File

My style in creating a view in codeIgniter is having a master template then include those files that are frequently change or updated during page transitions.

Out of our mockup template above we create a master template of our view. We take those part which can be reused in the entire site like the header, menu, side menu and the footer. This technique is really common in developing a PHP application.

Here we only have to prepare our view files for the next part of the tutorial. Open system/application/views folder, create a new file and we name it home_view.php, open it in a text editor and then populate the code below.

Our master view template is now ready. As you can see, its merely an html with one line of php code (<?php $this->load->view($template); ?>) that calls our page template view file which we will be adding soon as we go on in developing our application.

The next part of this tutorial, we will be making use of our template just made. We have to make our site’s hompage work dynamically. The product feature slideshow must be dynamically generated in our application.

About the author: insic

Subscribe in my RSS Feed for more updates on Web Design and Development related articles. Follow me on twitter or drop a message to my inbox.