An introduction to CodeIgniter

| | 3 min read

CodeIgniter is an open source PHP frame work with simple MVC pattern. CodeIgniter is lightweight, generates clean URLs and uses very simple template parser. CodeIgniter didn't require a specific template engine for website layout. Latest version of CodeIgniter is Version 3.0.0. It is a loosely coupled, faster, flexible and high performance system. It supported the database such as MySQL (5.1+), Oracle, MS SQL, PostgreSQL, SQLite, etc.

WORK FLOW CHART OF FRAMEWORK :

Working of CodeIgniter is based on MVC architecture. It is very simple and fast.

  • index.php file will serves the required output for the URL, by examining the Router files.
  • Router determine what should done with the http request.
  • Router determine the controller and controller loads the model, view and other required resources and send the rendered output to screen.

For example when the URL shows, www.mysite.com/article/health/latest. It means that there is a controller named “article” . This controller is simply a class , it has several methods to perform different tasks. Here the called method is 'health'. The job of method Health is fetch 'latest' articles related health from DB and render the result into view.

HELPERS ;

Helpers in CodeIgniter is a PHP files lies on application/helper folder. It is not a class it is a simple php file which contains different methods. For example,

<?php if (!defined('BASEPATH')) 
exit('No direct script access allowed');
if (!function_exists('myfirst_method')){
  function myfirst_method($var = '') {
   return $var;
  }
}?gt;

Save this as application/helpers/my_help.php. Now, this can be used in controller or view.

$this->load->helper('my_helper');
echo myfirst_method('Hello World');

This will automatically loaded by adding the new helper name in the configuration autoload function

$autoload['helper'] = array('new_helper','my_helper','other_helper');
CACHING :

Caching is possible in CodeIgniter. It is possible to enable file caching for your application by loading the cache driver.

CONFIG FILE

Default configuration file in CodeIgniter is application/config/config.php. Basic configuration setting and parameters are defined in this file. You can retrieve the config variable and values by config class. You can use your own custom config file instead of the default config file.

Config values are stored in the config file in an array $config. You can add your configuration items to this array. If you want to keep your own config file. Create a new file keep in config folder. But remember to keep the same format of the default file. Store your items in an array named $config. CodeIgniter will manage these files without conflicts.

The default config file will be loaded automatically by CodeIgniter. But for the custom config files you need to load it manually or automatically. For load the file manually, load the file within your controller in which where you required these customer settings, with the load function.

$this->config->load('filename');

If you need the custom config items all over the site, you can load it automatically by appending the files name into the auto load file. (application/config/autoload.php). You can simply retrieve a configuration item by,

$this->config->item('item name');

You get to know about another great open source frame work Drupal here. For additional information and support, you can contact our experts.