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.- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="language" content="en" />
- <title>Building an e-commerce application using CodeIgniter</title>
- <link rel="stylesheet" href="css/default.css" type="text/css" />
- <script type="text/javascript" src="js/jquery.js"></script>
- <script type="text/javascript" src="js/s3Slider.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#slider1').s3Slider({
- timeOut: 8000
- });
- });
- </script>
- </head>
- <body>
- <!-- wrap starts here -->
- <div id="wrap">
- <!--header -->
- <div id="header">
- <h1 id="logo-text"><a href="#">INSIC Shop</a></h1>
- <p id="slogan">E-Commerce Site Powered by CodeIgniter</p>
- </div>
- <!-- navigation -->
- <div id="menu">
- <ul>
- <li ><a href="home">Home</a></li>
- <li ><a href="about-us">About Us</a></li>
- <li ><a href="contact">Contact Us</a></li>
- </ul>
- </div>
- <!-- content-wrap starts here -->
- <div id="content-wrap">
- <div id="main">
- <h2>Featured Product</h2>
- <div id="slider1">
- <ul id="slider1Content">
- <li class="slider1Image">
- <a href=""><img src="products/product-3.jpg" alt="1" /></a>
- <span class="bottom"><strong>Product 3</strong><br />Praesent eros nibh, In risus nunc, tincidunt nec, bibendum ac, adipiscing vitae, enim. Aliquam faucibus volutpat elit. Aenean eu lacus. Sed arcu. Mauris aliquam.<br /><a href="#">Buy Now</a> »</span></li>
- <li class="slider1Image">
- <a href=""><img src="products/product-2.jpg" alt="2" /></a>
- <span class="bottom"><strong>Product 2</strong><br />Praesent eros nibh, In risus nunc, tincidunt nec, bibendum ac, adipiscing vitae, enim. Aliquam faucibus volutpat elit.<br /><a href="#">Buy Now</a> »</span></li>
- <li class="slider1Image">
- <a href=""><img src="products/product-1.jpg" alt="3" /></a>
- <span class="bottom"><strong>Product 1</strong><br />Praesent eros nibh, In risus nunc, tincidunt nec, bibendum ac, adipiscing vitae, enim.<br /><a href="#">Buy Now</a> »</span></li>
- <div class="clear slider1Image"></div>
- </ul>
- </div>
- <h2>Our Products</h2>
- <div class="box-list"><img src="products/thumb/product-1.jpg" width="120px"><strong><a href="#">Product 1</a></strong><br />Short description goes here<br /><span class="button"><a href="#">Buy Now</a> »</span></div>
- <div class="box-list"><img src="products/thumb/product-2.jpg" width="120px"><strong><a href="#">Product 2</a></strong><br >Short description goes here<br /><span class="button"><a href="#">Buy Now</a> »</span></div>
- <div class="box-list"><img src="products/thumb/product-3.jpg" width="120px"><strong><a href="#">Product 3</a></strong><br >Short description goes here<br /><span class="button"><a href="#">Buy Now</a> »</span></div>
- <div class="box-list"><img src="products/thumb/product-3.jpg" width="120px"><strong><a href="#">Product 4</a></strong><br />Short description goes here<br /><span class="button"><a href="#">Buy Now</a> »</span></div>
- <div class="box-list"><img src="products/thumb/product-1.jpg" width="120px"><strong><a href="#">Product 5</a></strong><br >Short description goes here<br /><span class="button"><a href="#">Buy Now</a> »</span></div>
- <div class="box-list"><img src="products/thumb/product-2.jpg" width="120px"><strong><a href="#">Product 6</a></strong><br >Short description goes here<br /><span class="button"><a href="#">Buy Now</a> »</span></div>
- </div>
- <div id="sidebar">
- <h2>Product Search</h2>
- <form action="#" class="searchform">
- <p>
- <input name="search_query" class="textbox" type="text" />
- <input name="search" class="button" value="Search" type="submit" />
- </p>
- </form>
- <h2>Product Category</h2>
- <ul class="sidemenu">
- <li ><a href="#">Category 1</a></li>
- <li ><a href="#">Category 2</a></li>
- <li ><a href="#">Category 3</a></li>
- <li ><a href="#">Category 4</a></li>
- </ul>
- </div>
- <!-- content-wrap ends here -->
- </div>
- <!--footer starts here-->
- <div id="footer">
- <p> © 2008-2009 <a href="http://insicdesigns.com">INSIC Designs.</a> |
- Valid <a href="http://validator.w3.org/check?uri=referer"> XHTML </a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> </p>
- </div>
- <!-- wrap ends here -->
- </div>
- </body>
- </html>
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.- * { margin: 0; padding: 0; outline: 0; }
- body {
- background: #caced1 url(../images/body-bg.gif) repeat-x top;
- font: 70%/1.5em Verdana, Tahoma, arial, sans-serif;
- color: #777;
- text-align: center;
- margin: 0;
- }
- /* links */
- a, a:visited {
- text-decoration: none;
- background: inherit;
- color: #FB9233;
- }
- a:hover {
- text-decoration: underline;
- background: inherit;
- color: #93C600;
- }
- /* headers */
- h1, h2, h3 { font-family: 'Trebuchet MS', Tahoma, Sans-serif; }
- h1 {
- font-size: 180%;
- font-weight: normal;
- color: #555;
- }
- h2 {
- font-size: 160%;
- color: #88ac0b;
- font-weight: normal;
- }
- h3 {
- font-size: 135%;
- color: #666666;
- }
- /* images */
- img {
- background: #fff;
- border: 1px solid #E5E5E5;
- padding: 5px;
- }
- img.float-rightright { margin: 5px 0px 10px 10px; }
- img.float-left { margin: 5px 10px 10px 0px; }
- h1, h2, h3, p {
- margin: 10px 15px;
- padding: 0;
- }
- ol {
- margin: 5px 15px;
- padding: 0 25px;
- }
- /* search form */
- .searchform {
- background-color: transparent;
- border: none;
- margin: 0;
- padding: 5px 0 5px 0;
- width: 180px;
- }
- .searchform p { margin: 0; padding: 0; }
- .searchform input.textbox {
- width: 110px;
- color: #777;
- padding: 2px;
- }
- .searchform input.button {
- width: 55px;
- }
- /********************************************
- LAYOUT
- ********************************************/
- #wrap {
- width: 790px;
- margin: 0 auto;
- text-align: left;
- }
- #content-wrap {
- clear: both;
- width: 760px;
- margin: 5px auto;
- padding: 0;
- }
- #header {
- background:url(../images/header.gif) no-repeat top left;
- position: relative;
- height: 144px;
- padding: 0;
- color: #fff;
- }
- #header h1#logo-text {
- margin: 0;
- padding: 45px 0 0 25px;
- }
- #header h1#logo-text a {
- margin: 0;
- padding: 0;
- font: bold 40px Arial, Sans-serif;
- color: #d7f000;
- text-transform: none;
- text-decoration: none;
- background: transparent;
- }
- #header p#slogan {
- margin: 0;
- padding-left: 25px;
- font: bold 13px 'Trebuchet MS', Arial, Sans-serif;
- text-transform: none;
- color: #c2c2c2;
- }
- /* navigation */
- #menu {
- clear: both;
- margin: 0 auto; padding: 0;
- background: #81C524 url(../images/menu.gif) repeat-x;
- font: bold 13px/40px Arial, Tahoma, Sans-serif;
- height: 43px;
- width: 790px;
- }
- #menu ul {
- float: left;
- list-style: none;
- margin:0; padding: 0 0 0 20px;
- }
- #menu ul li {
- display: inline;
- }
- #menu ul li a {
- display: block;
- float: left;
- padding: 0 12px;
- color: #323232;
- text-decoration: none;
- }
- #menu ul li a:hover {
- color: #323232;
- text-decoration:underline;
- background:#d2d2d2;
- }
- #menu ul li#current a {
- color: #323232;
- text-decoration:underline;
- }
- /* Main Column */
- #main {
- float: left;
- width: 555px;
- margin: 0; padding: 20px 0 0 0;
- display: inline;
- background: #fff;
- padding-bottom: 25px;
- border:1px solid #b4b8bb;
- }
- #main h2 {
- font: normal 180% 'Trebuchet MS', Tahoma, Arial, Sans-serif;
- padding: 0;
- margin-bottom: 0;
- color: #2666c3;
- }
- #main h2 a {
- color: #2666c3;
- text-decoration: none;
- }
- #main p, #main h1, #main h2, #main h3, #main ol,
- #main blockquote, #main table, #main form {
- margin-left: 20px;
- margin-right: 25px;
- }
- #main ul li {
- list-style-image: url(bullet.gif);
- }
- /* Sidebar */
- #sidebar {
- float: rightright;
- width: 195px;
- padding: 0; margin: 10px 0 0 0;
- color: #777;
- }
- #sidebar h2 {
- margin: 15px 5px 10px 5px;
- font: bold 1.4em 'Trebuchet MS', Tahoma, Sans-serif;
- color: #555;
- }
- #sidebar p {
- margin-left: 5px;
- }
- #sidebar ul.sidemenu {
- list-style: none;
- text-align: left;
- margin: 7px 10px 8px 0; padding: 0;
- text-decoration: none;
- border-top: 1px solid #b4b8bb;
- }
- #sidebar ul.sidemenu li {
- list-style: none;
- padding: 4px 0 4px 5px;
- margin: 0 2px;
- color: #777;
- border-bottom: 1px solid #e2e2e2;
- }
- * html body #sidebar ul.sidemenu li {
- height: 1%;
- }
- #sidebar ul.sidemenu li a {
- text-decoration: none;
- color: #1773BC;
- }
- #sidebar ul.sidemenu li a:hover {
- color: #333;
- }
- #sidebar ul.sidemenu ul { margin: 0 0 0 5px; padding: 0; }
- #sidebar ul.sidemenu ul li { border: none; }
- /* Footer */
- #footer {
- color: #323232;
- background: #caced1;
- clear: both;
- width: 790px;
- height: 57px;
- text-align: left;
- font-size: 90%;
- padding-left: 25px;
- }
- #footer p {
- padding: 10px 0;
- margin: 0;
- }
- #footer a {
- color: #0076ce;
- text-decoration: none;
- }
- /* alignment classes */
- .float-left { float: left; }
- .float-rightright { float: rightright; }
- .align-left { text-align: left; }
- .align-rightright { text-align: rightright; }
- /* display and additional classes */
- .clear { clear: both; }
- .submitf{
- padding:10px 0 0 45px;
- }
- .box-list { float:left; width: 130px; height:200px; margin:20px;}
- .error, .notice, .success {padding:.8em;margin-bottom:1em;border:2px solid #ddd;}
- .error {background:#FBE3E4;color:#8a1f11;border-color:#FBC2C4;}
- .notice {background:#FFF6BF;color:#514721;border-color:#FFD324;}
- .success {background:#E6EFC2;color:#264409;border-color:#C6D880;}
- .error a {color:#8a1f11;}
- .notice a {color:#514721;}
- .success a {color:#264409;}
- /* s3Slider Styles*/
- #slider1 {
- width: 512px; /* important to be same as image width */
- height: 278px; /* important to be same as image height */
- position: relative; /* important */
- overflow: hidden; /* important */
- background: #fff;
- border: 2px solid #323232;
- margin: 20px 20px;
- }
- #slider1 img{
- border: none;
- }
- #slider1Content {
- width: 512px; /* important to be same as image width or wider */
- position: absolute;
- top: 0;
- margin:0;
- }
- .slider1Image {
- float: left;
- display: none;
- border: none;
- }
- .slider1Image span {
- position: absolute;
- font: 10px/15px Arial, Helvetica, sans-serif;
- padding: 10px 13px;
- width: 512px;
- background-color: #000;
- filter: alpha(opacity=70);
- -moz-opacity: 0.7;
- -khtml-opacity: 0.7;
- opacity: 0.7;
- color: #fff;
- display: none;
- margin-left: 0;
- }
- .clear {
- clear: both;
- }
- .slider1Image span strong {
- font-size: 14px;
- }
- .bottombottom {
- bottombottom: 0;
- left: 0;
- height: 70px;
- width:512px; !important
- }
- ul {
- list-style-type: none;
- margin: 0;
- padding: 0;
- }
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.- <?php
- lass TestView extends Controller{
- function TestView ()
- {
- parent::Controller();
- $this->load->library('parser');
- $this->load->helper('url');
- }
- function index()
- {
- $data = array();
- $this->parser->parse('template', $data);
- }
<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.- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <base href="{ base_url }" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="language" content="en" />
- <title>Building an e-commerce application using CodeIgniter - {title}</title>
- <link rel="stylesheet" href="public/css/default.css" type="text/css" />
- <script type="text/javascript" src="public/js/jquery.js"></script>
- <script type="text/javascript" src="public/js/s3Slider.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#slider1').s3Slider({
- timeOut: 8000
- });
- });
- </script>
- </head>
- <body>
- <!-- wrap starts here -->
- <div id="wrap">
- <!--header -->
- <div id="header">
- <h1 id="logo-text"><a href="#">INSIC Shop</a></h1>
- <p id="slogan">E-Commerce Site Powered by CodeIgniter</p>
- </div>
- <!-- navigation -->
- <div id="menu">
- <ul>
- <li ><a href="home">Home</a></li>
- <li ><a href="about-us">About Us</a></li>
- <li ><a href="contact">Contact Us</a></li>
- </ul>
- </div>
- <!-- content-wrap starts here -->
- <div id="content-wrap">
- <div id="main"> <!-- Start of Main -->
- <!-- Load Our page template here -->
- <?php $this->load->view($template); ?>
- </div> <!--Main End -->
- <div id="sidebar">
- <h2>Product Search</h2>
- <form action="home/search" class="searchform">
- <p>
- <input name="search_query" class="textbox" type="text" />
- <input name="search" class="button" value="Search" type="submit" />
- </p>
- </form>
- <h2>Product Category</h2>
- <ul class="sidemenu">
- {categories}
- </ul>
- </div>
- <!-- content-wrap ends here -->
- </div>
- <!--footer starts here-->
- <div id="footer">
- <p> © 2008-2009 <a href="http://insicdesigns.com">INSIC Designs.</a> |
- Valid <a href="http://validator.w3.org/check?uri=referer"> XHTML </a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> </p>
- </div>
- <!-- wrap ends here -->
- </div>
- </body>
- </html>
<?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.
No comments:
Post a Comment