Professional CodeIgniter

(singke) #1

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’);
Free download pdf