Professional CodeIgniter, Thomas Myer

Chapter 7: Improving the Dashboard
215
While you ' re at it, create a
getActiveColors()

function as well. You need it shortly:
function getActiveColors(){
$data = array();
$this-
>
db-
>
select(`id,name');
$this-
>
db-
>
where(`status','active');
$Q = $this-
>
db-
>
get(`colors');
if ($Q-
>
num_rows()
>
0){
foreach ($Q-
>
result_array() as $row){
$data[$row[`id']] = $row[`name'];
}
}
$Q-
>
free_result();
return $data;
}

It ' s time to start creating views. The first is admin_colors_home. It ' s almost exactly the same as the
admin_admins_home view, so just duplicate that one and make the necessary tweaks to point to colors -

based views, controller functions, and data arrays.
<
h1
>
<
?php echo $title;?
>
<
/h1
>
<
p
>
<
?php echo anchor("admin/colors/create", "Create new color");?
>
<
?php
if ($this-
>
session-
>
flashdata(`message')){
echo "
<
div class='message'
>
".$this-
>
session-
>
flashdata(`message')."
<
/div
>
";
}
if (count($colors)){
echo "
<
table border='1' cellspacing='0' cellpadding='3' width='400'
>
\n";
echo "
<
tr valign='top'
>
\n";
echo "
<
th
>
ID
<
/th
>
\n
<
th
>
Name
<
/th
>
<
th
>
Status
<
/th
>
<
th
>
Actions
<
/th
>
\n";
echo "
<
/tr
>
\n";
foreach ($colors as $key =
>
$list){
echo "
<
tr valign='top'
>
\n";
echo "
<
td
>
".$list[`id']."
<
/td
>
\n";
echo "
<
td
>
".$list[`name']."
<
/td
>
\n";
echo "
<
td align='center'
>
".$list[`status']."
<
/td
>
\n";
echo "
<
td align='center'
>
";
echo anchor(`admin/colors/edit/'.$list[`id'],'edit');
echo " | ";
echo anchor(`admin/colors/delete/'.$list[`id'],'delete');
echo "
<
/td
>
\n";
echo "
<
/tr
>
\n";
}
echo "
<
/table
>
";
}
?
>
c07.indd 215
c07.indd 215
6/10/08 5:36:47 PM
6/10/08 5:36:47 PM


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

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