Professional CodeIgniter

(singke) #1

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 > ”;
}
? >
Free download pdf