Professional CodeIgniter, Thomas Myer
Chapter 5: Building a Shopping Cart
130
Figure 5-9
Fixing the Header
The header portion of the site is currently maintained in the header view. From a design perspective,
there are a few design and usability problems with the items in that view. For example, the search widget
is too wide, and the links don ' t particularly look like navigation items. They just look like a list of words.
In this section, you remedy these problems.
First, though, open the /system/application/views/header.php in your editor. The first thing you ' re
going to do is wrap the entire contents of the file (except for the image) into a
<
div
>
tag with ID
globalnav
. Inside that div, you ' re going to put in a
<
ul
>
tag, and wrap each of your links in an
<
li
>
tag. That goes for the search form as well!
Once every item in the navigation is in an
<
li
>
tag, you can reduce the width of the search field by
setting the size variable of the
$data
array to something like 15.
Finally, you can add a very simple bit of code to detect whether you ' re on the home page by using
$this
-
>
uri
-
>
segment()
. If you ' re on the home page, don ' t show a link to Home. If you ' re not, then
show the visitor a link he can click to go Home.
Why are you suddenly using
$this
-
>
uri
-
>
segment()
when you were simply assigning incoming
segments to an argument in the controller? First of all, you ' re working inside the view, not the
controller, and thus it makes sense to use this function in this context. Second of all, you ' re looking at
controller, and thus it makes sense to use this function in this context. Second of all, you ' re looking at
c05.indd 130
c05.indd 130
6/10/08 5:35:23 PM
6/10/08 5:35:23 PM