Professional CodeIgniter

(singke) #1

Chapter 6: Creating a Dashboard


174


Figure 6-10

Creating the Product Edit Page


The edit() function of the admin/products controller is pretty much a clone of the create() process,
except that you have to load in the existing product information. Without further ado, here ’ s the edit()
function itself:

function edit($id=0){
if ($this- > input- > post(‘name’)){
$this- > MProducts- > updateProduct();
$this- > session- > set_flashdata(‘message’,’Product updated’);
redirect(‘admin/products/index’,’refresh’);
}else{

$data[‘title’] = “Edit Product”;
$data[‘main’] = ‘admin_product_edit’;
$data[‘product’] = $this- > MProducts- > getProduct($id);
$data[‘categories’] = $this- > MCats- > getCategoriesDropDown();
$this- > load- > vars($data);
$this- > load- > view(‘dashboard’);
}
}
Free download pdf