Professional CodeIgniter

(singke) #1

Chapter 6: Creating a Dashboard


168


Start with the controller by creating a simple delete() function:

function delete($id){

$this- > MCats- > deleteCategory($id);
$this- > session- > set_flashdata(‘message’,’Category deleted’);
redirect(‘admin/categories/index’,’refresh’);
}

Once more, you ’ re pulling the category ID you need as an argument to the function, passing that ID to
the deleteCategory() function in your MCats model, then redirecting the user back to the category
index page.

Here ’ s the deleteCategory() function. It is very simple — consisting of a query that sets a given
category ’ s status to inactive.

function deleteCategory($id){
$data = array(‘status’ = > ‘inactive’);
$this- > db- > where(‘id’, $id);
$this- > db- > update(‘categories’, $data);
}

There ’ s no view involved in this, but you should still see a status message, as pictured in Figure 6 - 8.

Figure 6-8
Free download pdf