Chapter 3: A 10,000 - Foot View of CodeIgniter
72
This CSS file is undeniably simple (almost too simple!), but it will get you where you need to go. It
establishes some basic structures you can use inside your templates, such as a wrapper div to contain
your other containers (such as header, footer, main content, navigation, etc.).
As you refine the project, you ’ ll have plenty of time to revisit this file and add more display rules (for
links, bulleted lists, etc.).
Creating the Category View
Now that you ’ ve established a simple CSS file, it ’ s time to create a generic Template view that you can
reuse throughout your application. In this master template, which you can name template.php , are a series
of embedded PHP calls that load certain subviews, such as header, navigation, and footer.
These subviews contain the HTML and PHP that you will create in the next few sections. Notice in the
following code that you ’ re also trying to load a subview with $main. This variable will contain the name
of a subview that is dynamically set within the controller and allows you a great deal of flexibility as you
code your application. In Chapter 4 , you learn how to use this functionality. For now, you can use a
simple placeholder.
< !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” / >
< title > < ?php echo $title;? > < /title >
< link href=” < ?= base_url();? > css/default.css” rel=”stylesheet” type=”text/css” / >
< script type=”text/javascript” >
// < ![CDATA[
base_url = ‘ < ?= base_url();? > ’;
//]] >
< /script >
< /head >
< body >
< div id=”wrapper” >
< div id=”header” >
< ?php $this- > load- > view(‘header’);? >
< /div >
< div id=”nav” >
< ?php $this- > load- > view(‘navigation’);? >
< /div >
< div id=”main” >
< ?php $this- > load- > view($main);? >
< /div >
< div id=”footer” >
< ?php $this- > load- > view(‘footer’);? >
< /div >
< /div >
< /body >
< /html >
Save this file as template.php in the /system/application/views folder.