Professional CodeIgniter, Thomas Myer

Chapter 6: Creating a Dashboard
169

That ' s it! Claudia now has a working administrative tool that will let her manage her categories. Yes,
there are some questions that have gone unanswered at this point (especially surrounding deleted
categories and how to handle orphaned products), but it ' s good enough for now. Chapter 7 is where you
figure out how to handle those little details.

It ' s time to create some Product management tools in the same vein.


Creating the Product Management Tools

By now you understand how to build out administrative screens with CodeIgniter, so it won ' t come as
any surprise to you that by and large you ' ll be able to reuse the Category code you just wrote to expedite
the creation of the products section.

Indeed, the only thing different about the Product tools is that you have to allow for the uploading of an
image and a thumbnail for each product, but other than that, you ' re dealing with pretty much the same
kind of information.


Creating the Product Home Page
Here ' s the
index()

function, which makes use of the MProducts model to retrieve all products:
function index(){
$data[`title'] = "Manage Products";
$data[`main'] = `admin_product_home';
$data[`products'] = $this-
>
MProducts-
>
getAllProducts();
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}

The admin_product_home view is pretty much the same as the admin_cat_home view, except that
you ' re looping through a
$products

array instead of a
$categories
array.
<
h1
>
<
?php echo $title;?
>
<
/h1
>
<
p
>
<
?php echo anchor("admin/products/create", "Create new product");?
>
<
/p
>
<
?php
if ($this-
>
session-
>
flashdata(`message')){
echo "
<
div class='message'
>
".$this-
>
session-
>
flashdata(`message')."
<
/div
>
";
}
if (count($products)){
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 ($products 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";
c06.indd 169
c06.indd 169
6/10/08 5:36:04 PM
6/10/08 5:36:04 PM


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

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