Professional CodeIgniter, Thomas Myer
Chapter 6: Creating a Dashboard
181
Figure 6-12
Creating the User Create Page
Here ' s the
create()
function for the admin/admins controller:
function create(){
if ($this-
>
input-
>
post(`username')){
$this-
>
MAdmins-
>
addUser();
$this-
>
session-
>
set_flashdata(`message','User created');
redirect(`admin/admins/index','refresh');
}else{
$data[`title'] = "Create User";
$data[`main'] = `admin_admins_create';
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}
}
There ' s nothing new or fancy here. Check for POST data. If you see any, use the
addUser()
function to
add the user. If not, show the admin_admins_create view. Here ' s that view -- a simple form:
<
h1
>
<
?php echo $title;?
>
<
/h1
>
<
?php
echo form_open(`admin/admins/edit');
c06.indd 181
c06.indd 181
6/10/08 5:36:08 PM
6/10/08 5:36:08 PM