Tag Archive: codeigniter


CodeIgniter 2.0

CodeIgniter 2.0 is a new version after CodeIgniter 1.7.2. You can not update as simple as version before like from 1.7.1 to 1.7.2, using replace files and directories in ‘system’ folder. As of CodeIgniter 2.0, Scaffolding and Plugins have been removed. But developers are encouraged to refactor existing plugins as helpers or libraries.

There is a new feature of Loader Class in this version. That is Application ‘Package’ which allows for the easy distribution of complete sets of resource in a single directory complete with its own libraries, models, helpers, config and language files. It is recommended that these packages be placed in the application/third_party folder. Lets see a sample map of an package directory:
Sample Package named ‘Left Bar’ on a Directory Map:

/application/third_party/foo_bar

config/
helpers/
language/
libraries/
models/

It has it’s own config files, helpers, language files, libraries, and models. How to use this resource in controllers, you can read fully in CodeIgniter 2.0 user_guide/libraries/loader.html.

Core System Classes
Every time CodeIgniter runs there are several base classes that are initialized automatically. It is possible to swap any of the core system classes with your own version. To use your own class please place on local application/core/your_class.php. In 1.7.2 or before you should place on application/libraries/your_class.php.

To download and see the fully significant about CodeIgniter 2.0 please visit ellislab.

Connecting Multiple Database

If you want to know how to connect to multiple databases in Codeigniter, I’m going to show you.
Step 1:
Open file database.php in the application/config folder.
Step 2:
Find database settings and make a secondary database details in this file. For example:

$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";

//And copy and paste listing above like this:

$db['sec_db']['hostname'] = "localhost";
$db['sec_db']['username'] = "root";
$db['sec_db']['password'] = "";
$db['sec_db']['database'] = "blog";
$db['sec_db']['dbdriver'] = "mysql";
$db['sec_db']['dbprefix'] = "";
$db['sec_db']['pconnect'] = TRUE;
$db['sec_db']['db_debug'] = TRUE;
$db['sec_db']['cache_on'] = FALSE;
$db['sec_db']['cachedir'] = "";
$db['sec_db']['char_set'] = "utf8";
$db['sec_db']['dbcollat'] = "utf8_general_ci";

As we can see that I have sec_db as secondary database. Don’t forget to change the Controller to load the model and of course the Model to connect to the sec_db.

MVC

MVC is a design pattern used by applications that need the ability to
maintain multiple views of the same data. The MVC pattern has been separated into Models for maintaining data, Views for displaying data and Controller for handling events that affect the model or view. Hmm sound interesting design pattern.

And the CodeIgniter is an MVC framework for PHP. In CodeIgniter we could separates application logic from presentation. It will be easier for programmers to modify and develop the system in the future.
As we can see in CodeIgniter User Guide, with MVC 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.

Even CodeIgniter has complexity separation, you still can build your application minimally using Controllers and Views. And of course CodeIgniter also enables you to incorporate your own existing scripts, or even develop core libraries for the system, so you work as you need.
It is a glance about MVC and CodeIgniter, Interest to try :) .

Powered by WordPress.