Professional CodeIgniter

(singke) #1

Chapter 6: Creating a Dashboard


161


There ’ s nothing surprising here. You ’ re merely calling up a list of categories using getAllCategories()
and feeding it to a subview called admin_cat_home.


The admin_cat_home subview is also very simple. It loops through the category listing provided by the
controller and prints out an ID, name, status, and a list of actions (edit and delete) for each one. Notice
that this isn ’ t anything terribly exciting or even complicated.


< h1 > < ?php echo $title;? > < /h1 >
< p > < ?php echo anchor(“admin/categories/create”, “Create new category”);? > < /p >
< ?php
if ($this- > session- > flashdata(‘message’)){
echo “ < div class=’message’ > ”.$this- > session- > flashdata(‘message’).” < /div > ”;
}
if (count($categories)){
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 ($categories 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/categories/edit/’.$list[‘id’],’edit’);
echo “ | “;
echo anchor(‘admin/categories/delete/’.$list[‘id’],’delete’);
echo “ < /td > \n”;
echo “ < /tr > \n”;
}
echo “ < /table > ”;
}
? >

At the top of the page there is a link that allows users to create a new category if needed. The use of
flashdata is again in evidence. You ’ ll use it very soon to display information from actions taken by
the admin.

Before moving on to create that part of the application, take a look at your new page. It should look like
Figure 6 - 5.
Free download pdf