Professional CodeIgniter, Thomas Myer

Chapter 6: Creating a Dashboard
162
Figure 6-5


Creating the Category Create View
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');
c06.indd 162
c06.indd 162
6/10/08 5:36:02 PM
6/10/08 5:36:02 PM


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.