Chapter 6: Creating a Dashboard
183
Creating the User Edit Page
Without belaboring the obvious, here ’ s the edit() function in the admin/admins controller:
function edit($id=0){
if ($this- > input- > post(‘username’)){
$this- > MAdmins- > updateUser();
$this- > session- > set_flashdata(‘message’,’User updated’);
redirect(‘admin/admins/index’,’refresh’);
}else{
$data[‘title’] = “Edit User”;
$data[‘main’] = ‘admin_admins_edit’;
$data[‘admin’] = $this- > MAdmins- > getUser($id);
$this- > load- > vars($data);
$this- > load- > view(‘dashboard’);
}
}
Very much the same thing is being done as in the other edit functions. Check for POST data. If you see
any, run updateUser() , and redirect the user back to the admins home page. If you don ’ t see any POST
data, load the admin_admins_edit view.
The admin_admins_edit view is a simple form. The same rules apply for this Edit form as with all the rest.
< h1 > < ?php echo $title;? > < /h1 >
< ?php
echo form_open(‘admin/admins/edit’);
echo “ < p > < label for=’uname’ > Username < /label > < br/ > ”;
$data = array(‘name’= > ’username’,’id’= > ’uname’,’size’= > 25,
‘value’= > $admin[‘username’]);
echo form_input($data) .” < /p > ”;
echo “ < p > < label for=’email’ > Email < /label > < br/ > ”;
$data = array(‘name’= > ’email’,’id’= > ’email’,’size’= > 50, ‘value’= > $admin[‘email’]);
echo form_input($data) .” < /p > ”;
echo “ < p > < label for=’pw’ > Password < /label > < br/ > ”;
$data = array(‘name’= > ’password’,’id’= > ’pw’,’size’= > 25,
‘value’= > $admin[‘password’]);
echo form_password($data) .” < /p > ”;
echo “ < p > < label for=’status’ > Status < /label > < br/ > ”;
$options = array(‘active’ = > ‘active’, ‘inactive’ = > ‘inactive’);
echo form_dropdown(‘status’,$options, $admin[‘status’]) .” < /p > ”;
echo form_hidden(‘id’,$admin[‘id’]);
echo form_submit(‘submit’,’update admin’);
echo form_close();
? >
When you ’ re done working on the edit function, you should end up with something that looks like
Figure 6 - 14.