Professional CodeIgniter, Thomas Myer
Chapter 6: Creating a Dashboard
180
Creating the User Home Page
The user home page is called with the
index()
function. Just as with the product and category home
page, the function loads a view and provides a listing of all users (thanks to your MAdmins
getAllUsers()
function!) to that view.
function index(){
$data[`title'] = "Manage Users";
$data[`main'] = `admin_admins_home';
$data[`admins'] = $this-
>
MAdmins-
>
getAllUsers();
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}
The view itself, admin_admins_home, is pretty much a clone of the other home pages except that you ' ll
be looping on the
$admins
array and using username instead of name while printing.
<
h1
>
<
?php echo $title;?
>
<
/h1
>
<
p
>
<
?php echo anchor("admin/admins/create", "Create new user");?
>
<
?php
if ($this-
>
session-
>
flashdata(`message')){
echo "
<
div class='message'
>
".$this-
>
session-
>
flashdata(`message')."
<
/div
>
";
}
if (count($admins)){
echo "
<
table border='1' cellspacing='0' cellpadding='3' width='400'
>
\n";
echo "
<
tr valign='top'
>
\n";
echo "
<
th
>
ID
<
/th
>
\n
<
th
>
Username
<
/th
>
<
th
>
Status
<
/th
>
<
th
>
Actions
<
/th
>
\n";
echo "
<
/tr
>
\n";
foreach ($admins as $key =
>
$list){
echo "
<
tr valign='top'
>
\n";
echo "
<
td
>
".$list[`id']."
<
/td
>
\n";
echo "
<
td
>
".$list[`username']."
<
/td
>
\n";
echo "
<
td align='center'
>
".$list[`status']."
<
/td
>
\n";
echo "
<
td align='center'
>
";
echo anchor(`admin/admins/edit/'.$list[`id'],'edit');
echo " | ";
echo anchor(`admin/admins/delete/'.$list[`id'],'delete');
echo "
<
/td
>
\n";
echo "
<
/tr
>
\n";
}
echo "
<
/table
>
";
}
?
>
At the end of the process, your admin home page should look like Figure 6 - 12 .
c06.indd 180
c06.indd 180
6/10/08 5:36:08 PM
6/10/08 5:36:08 PM