Chapter 6: Creating a Dashboard
162
Figure 6-5
Creating the Category Management Tools
Now it ’ s time to create a simple form that will allow Claudia to create a new category whenever she
wants. Before jumping into the code, you have to know that this new create() function will pull
double duty.
If you need a quick reminder of how to build forms in CodeIgniter, refer to ” The Form Helper ” section in
Chapter 3.
First, it checks to see if there are any incoming POST data (and specifically, a name field). If there are
POST data, it runs the addCategory() function in the MCats model. You haven ’ t created that function
yet, but you will.
If no POST data are detected, it displays the dashboard view, loading the admin_cat_create view into
$data[‘main’]. Also, it loads the top - level categories using getTopCategories(). Don ’ t worry —
you haven ’ t created this function yet.
Before you start working in the model to create those two functions, create your create() function:
function create(){
if ($this- > input- > post(‘name’)){
$this- > MCats- > addCategory();
$this- > session- > set_flashdata(‘message’,’Category created’);