Professional CodeIgniter

(singke) #1

Chapter 3: A 10,000 - Foot View of CodeIgniter


64


Finally, the redirect() function allows you to create redirects in case of different problems. In the
above example that involved the Session library, note the use of the redirect() function if an e - mail is
not set correctly:

if ($this- > session- > userdata(‘email’) != ‘[email protected]’){
redirect(‘admin/logout’, ‘refresh’);
}

The refresh() function takes two arguments. The first is the destination for the redirect, and the second
argument can be either “ location ” or “ refresh. ” Most of the time, you ’ ll use the “ refresh ” option as the
second argument.

Creating Models, Views, and Controllers


At this point, you ’ re ready to start working with files that relate directly to your project — namely, the
models, views, and controllers that make up the heart of the application you ’ ll be building for Claudia.

Models and Database Tables


You received an extremely brief introduction to models, views, and controllers in Chapter 1 , so in this
section, you ’ ll concentrate on the database tables and models you ’ ll need for Claudia ’ s project. Before
you delve too deeply into constructing models for your tables, here ’ s a quick reminder of the tables ’
structures from Chapter 2 :

First, the categories table:

CREATE TABLE ‘categories’ (
‘id’ INT NOT NULL AUTO_INCREMENT ,
‘name’ VARCHAR( 255 ) NOT NULL ,
‘shortdesc’ VARCHAR( 255 ) NOT NULL ,
‘longdesc’ TEXT NOT NULL ,
‘status’ ENUM( ‘active’, ‘inactive’ ) NOT NULL ,
‘parentid’ INT NOT NULL ,
PRIMARY KEY ( ‘id’ )
) TYPE = MYISAM ;

Next, the products table:

CREATE TABLE ‘products’ (
‘id’ INT NOT NULL AUTO_INCREMENT ,
‘name’ VARCHAR( 255 ) NOT NULL ,
‘shortdesc’ VARCHAR( 255 ) NOT NULL ,
‘longdesc’ TEXT NOT NULL ,
‘thumbnail’ VARCHAR( 255 ) NOT NULL ,
‘image’ VARCHAR( 255 ) NOT NULL ,
‘sizes’ ENUM( ‘s’, ‘m’, ‘l’, ‘xl’ ) NOT NULL ,
‘colors’ ENUM( ‘red’, ‘blue’, ‘green’, ‘brown’, ‘white’, ‘black’ ) NOT NULL ,
‘grouping’ VARCHAR( 16 ) NOT NULL ,
‘status’ ENUM( ‘active’, ‘inactive’ ) NOT NULL ,
‘category_id’ INT NOT NULL ,
Free download pdf