Professional CodeIgniter, Thomas Myer

Chapter 4: Creating the Main Web Site
86
Since you ' re going to pass two arrays to the view, here ' s what that view, called home , looks like. Notice
that it is processing an array called
$mainf

(which will hold the main featured item) and
$sidef
(which
will contain a list of sidebar featured products).
<
div id='pleft'
>
<
?php
echo "
<
img src='".$mainf[`image']."' border='0' align='left'/
>
\n";
echo "
<
h2
>
".$mainf[`name']."
<
/h2
>
\n";
echo "
<
p
>
".$mainf[`shortdesc'] . "
<
br/
>
\n";
echo anchor(`welcome/product/'.$mainf[`id'],'see details') . "
<
br/
>
\n";
echo anchor(`welcome/cart/'.$mainf[`id'],'buy now') . "
<
/p
>
\n";
?
>
<
/div
>
<
div id='pright'
>
<
?php
foreach ($sidef as $key =
>
$list){
echo "
<
img src='".$list[`thumbnail']."' border='0' align='left'/
>
\n";
echo "
<
h4
>
".$list[`name']."
<
/h4
>
\n";
echo "
<
p
>
";
echo anchor(`welcome/product/'.$list[`id'],'see details') . "
<
br/
>
\n";
echo anchor(`welcome/cart/'.$list[`id'],'buy now') . "
<
/p
>
\n";
}
?
>
<
/div
>

Notice that the main feature is placed inside a div uniquely identified as pleft . The sidebar features are
placed inside a div uniquely identified as pright . Doing things this way allows you to create the
appropriate CSS rules for layout.

Before discussing anything else, it ' s good to talk about an alternative syntax using short tags. To use this
alternative syntax, you must have short tag support enabled on your PHP installation. Some developers
prefer this alternative syntax to what you see in the previous example. Some prefer the " old - fashioned
way. " There really is no difference other than your preference.

Here ' s what the previous example would look like with the alternative syntax:
<
div id='pleft'
>
<
img src='
<
?= $mainf[`image']; ?
>
' border='0' align='left'/
>
<
h2
>
<
?= $mainf[`name']; ?
>
<
/h2
>
<
p
>
<
?= $mainf[`shortdesc']; ?
>
<
br/
>
<
?= anchor(`welcome/product/'.$mainf[`id'],'see details');?
>
<
br/
>
<
?= anchor(`welcome/cart/'.$mainf[`id'],'buy now');?
>
<
/p
>
<
/div
>
<
div id='pright'
>
<
? foreach ($sidef as $key =
>
$list) : ?
>
<
img src='
<
?= $list[`thumbnail'];?
>
' border='0' align='left'/
>
<
h4
>
<
?= $list[`name'];?
>
<
/h4
>
<
p
>
<
?= anchor(`welcome/product/'.$list[`id'],'see details');?
>
<
br/
>
<
?= anchor(`welcome/cart/'.$list[`id'],'buy now');?
>
<
/p
>
<
? endforeach; ?
>
<
/div
>
c04.indd 86
c04.indd 86
6/10/08 5:34:22 PM
6/10/08 5:34:22 PM


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

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