Tuesday, September 9, 2008

Introduction to Codeigniter

In this article I will present to you the Codeigniter PHP Framework through a simple web application. The web app will show you how Codeigniter can be used to help in easily developing a simple web database application with Apache, MySQL and PHP.

I used the following setup on my server:
Apache 2.2 Web Server
PHP 5.2.5
MySQL 5.0

To start off, I will be guiding you through the process of installing the framework to you local web server. This will be the first past of a series of articles.

First, you need to get a copy of the latest build of Codeigniter (I used version 1.6.3). Unpack the file, rename the folder to "codeigniter" and then upload to your web server directory. Open config.php file which is located in the application/config directory inside the codeigniter folder and edit the base URL using your preferred text editor to something like this:


$config['base_url'] = "http://localhost/your-code-igniter-folder/";

Set the Index Page to this:

$config['index_page'] = '';

To enable security set XSS_filtering to TRUE, and then I suggest you also set rewrite_short_tags to TRUE to be able to use short tags without editing php.ini file.

Since we will be using MySQL database edit database.php with the following:

$db['default']['hostname'] = "your-hostname";
$db['default']['username'] = "your-username";
$db['default']['password'] = "your-password";
$db['default']['database'] = "your-database";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

We then have to edit autoload.php to be able to automatically load systems for codeigniter. For this project we need to load the url helper:

$autoload['helper'] = array('url');

Tip: The default controller loaded by codeigniter is welcome.php, to be able to edit this open routes.php and edit the following lines:

$route['default_controller'] = "welcome";

to something like this:

$route['default_controller'] = "main";

The next article will be on the actual code implemented in the application.

0 comments: