Chapter 6: Creating a Dashboard
165
Figure 6-6
Go ahead and test the form by creating a new category. You should see a success message when you add
the category.
Creating the Category Edit View
The edit category is pretty much just like the create category view, except you have to load the existing
category information into the form and you perform an update on the table instead of an insert.
Taking it step-by-step, first update the controller with an edit() function:
function edit($id=0){
if ($this- > input- > post(‘name’)){
$this- > MCats- > updateCategory();
$this- > session- > set_flashdata(‘message’,’Category updated’);
redirect(‘admin/categories/index’,’refresh’);
}else{
$data[‘title’] = “Edit Category”;
$data[‘main’] = ‘admin_cat_edit’;
$data[‘category’] = $this- > MCats- > getCategory($id);
$data[‘categories’] = $this- > MCats- > getTopCategories();
$this- > load- > vars($data);
$this- > load- > view(‘dashboard’);
}
}