Professional CodeIgniter, Thomas Myer

Chapter 4: Creating the Main Web Site
96



See how easy it is to make changes to CodeIgniter models in the face of requirements? You can start out
complex, or you can grow from simple to complex, but never would anyone characterize the process as
complicated. That ' s the beauty of a good MVC framework.
Finally, it ' s time to work directly on the category view. Luckily, you ' ve already built a similar view for
the home page, so you can use it as a rough model. Essentially, what you need to do is display the
category and listing information properly. Because you ' re passing in an array with three distinctive parts
(the category information, the listing, and what level the category lives on), you can easily create a
listing:
<
div id='pleft'
>
<
?php
echo "
<
h2
>
".$category[`name']."
<
/h2
>
\n";
echo "
<
p
>
".$category[`shortdesc'] . "
<
/p
>
\n";
foreach ($listing as $key =
>
$list){
echo "
<
img src='".$list[`thumbnail']."' border='0' align='left'/
>
\n";
echo "
<
h4
>
";
switch($level){
case "1":
echo anchor(`welcome/cat/'.$list[`id'],$list[`name']);
break;
case "2":
echo anchor(`welcome/product/'.$list[`id'],$list[`name']);
break;
}
echo "
<
/h4
>
\n";
echo "
<
p
>
".$list[`shortdesc']."
<
/p
>
<
br style='clear:both'/
>
";
}
?
>
<
/div
>

All in all, you just need a quick
switch()

statement to help build the proper links (to either the category
or product pages), and the result is something very close to Figure 4 - 8 (the category view) and Figure 4 - 9
(the subcategory view). Again, these views aren ' t perfect, and they certainly won ' t win any prizes at an
award ceremony, but they get the job done, and that ' s the focus of this section.
c04.indd 96
c04.indd 96
6/10/08 5:34:25 PM
6/10/08 5:34:25 PM


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.