Code Igniter Tutorial Part 1

What’s Code Igniter?

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.

Why Code Igniter?

  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.
  • You want a framework that requires nearly zero configuration.
  • You want a framework that does not require you to use the command line.
  • You want a framework that does not require you to adhere to restrictive coding rules.
  • You are not interested in large-scale monolithic libraries like PEAR.
  • You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).
  • You eschew complexity, favoring simple solutions.
  • You need clear, thorough documentation.

Code Igniter Benchmarking? here

Download the lastest version? here

How Code Igniter Works?


The following graphic illustrates how data flows throughout the system:

  1. The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
  2. The Router examines the HTTP request to determine what should be done with it.
  3. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
  4. Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
  5. The Controller loads the model, core libraries, plugins, helpers, and any other resources needed to process the specific request.
  6. The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.

What Is MVC?

CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

  • The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
  • The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of “page”.
  • The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.

CodeIgniter has a fairly loose approach to MVC since Models are not required. If you don’t need the added separation, or find that maintaining models requires more complexity than you want, you can ignore them and build your application minimally using Controllers and Views. CodeIgniter also enables you to incorporate your own existing scripts, or even develop core libraries for the system, enabling you to work in a way that makes the most sense to you.

Start Using Code Igniter

First download the last version of Code Igniter. In this tutorial I use Code Igniter version 1.7.2. Now you have codeigniter_1.7.2.zip file and extract it. This is default folder structure on code igniter.

Code igniter root directory contain system, and user_guide.  Now if you expand System diretory you’ll get application, cache, codeigniter, database, fonts, helpers, language, libraries, logs, plugins, and scaffolding. Your application will be placed on application directory. You’ll find Model, View, Controller inside application directory.

Ok. Now you need Apache server, PHP, and MySql. For this tutorial i use XAMPP(contain Apache, PHP, MySQL) You can download the exe package for Windows here. Install XAMPP on C directory till instalation finish and start MySql and Apache server from XAMPP control panel application. Put you codeigniter_1.7.2 on C:\xampp\htdocs\ and try to call it from your localhost.

Your instalation succedded for first time.

Prepare Your Database
First I created database Blog on MySql. Next, lets set up the underlying database for our blog. if you haven’t already done so, create an empty database for use in this tutorial, with a name of your choice. Right now, we’ll just create a single table to store our posts. We’ll also throw in a few posts right now to use for testing purposes. Execute the following SQL statements into your database:

/* First, create our posts table: */
CREATE TABLE posts (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(50),
    body TEXT,
    created DATETIME DEFAULT NULL,
    modified DATETIME DEFAULT NULL
);
 
/* Then insert some posts for testing: */
INSERT INTO posts (title,body,created)
    VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title,body,created)
    VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title,body,created)
    VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());

Code Igniter Database Configuration

Open your Codeigniter_1.7.2 on htdocs and open database.php file that locate on  Codeigniter_1.7.2->system->application->config->database.php

Change database configuration setting, username, password.

$active_group = "default";
$active_record = TRUE;
 
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "blog";
$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";

Default value of username is ‘root’, password keep empty, database is your database name ‘blog’.
Ok then save it.

To be continued on next post



Related Post:

Post a Comment

Your email is never published nor shared. You're allow to say what you want...

Blogroll Link Update