Codeigniter One of the best PHP framework

Nov 27, 2015

Alphanso Tech



Codeigniter One of the best PHP framework

Codeigniter is one of the popular and widely used framework out of many php based MVC frameworks. It has small footprint, minimalist architecture and fewer resources to load which makes the framework lighter and faster than it’s competitors.

Yes, we know the downside of singleton architecture it’s following, but the next major release i.e codeigniter 4 will be written ground up completely. It will eliminate the singleton pattern and will be based on the PHP 7! interesting isn’t it?

If you are working on mid scale web application project or you are a beginner to intermediate developer looking for a web development framework which is fast and easy to learn, I would recommend you have a look at codeigniter development framework.

If you are familiar with MVC concept, oop and basics of PHP you are good to go for your first MVC based web application using codeigniter.

If you want to jump start into the code igniter development, well we have this article for you guys.

The article will explain:

In this blog we will cover up following topics:

  1. What is MVC?
  2. Codeigniter structure architecture.
  3. Create a static program with controller and view.
    1. Installation of Codeigniter
    2. Basic configuration
    3. Attach database with Codeigniter.
  4. Interaction with model & view.
  5. Some basic Instruction regarding CI.

What is MVC?

MVC Architecture

MVC Architecture


Responsible for maintaining data.

Contains Business Logic.


Responsible for displaying all or a portion of the data to the user.

Does not store any data except to cache state.


Responsible for interactions between the Model and View.

Updates the view when the model changes

Codeigniter structure architecture

Let’s study the basic structure and architecture by taking an example of User Registranion.

CI basic Architecture

CI basic Architecture

Codeigniter One of the best PHP framework ,It was built for PHP coders who need a simple and elegant toolkit to create full-featured web applications.


Create a static program with controller and view

  • Installation Of CodeIgniter

Installation of CodeIgniter is quite simple. Just navigate Codeigniter official site,you will get the Download link.

  • Download the CodeIgniter latest version.
  • Extract the downloaded file and put it in your server folder Apache24/htdocs or Xampp/htdocs,vice versa.
  • Set base url at application/config/config.php i.e. $config[‘base_url’] = ‘http://localhost/ci/’.
  • Goto browser and run CI.
  • Attach database with Codeigniter

Attachment of database in CI is very easy.

  • Explore the CI structure.
  • Navigate to application/config/database.php.
  • At the bottom of the page you will get an array named $db.
  • Assign the host name, user name,password and the database name. Now your database has been connected with CI.

Now navigate to application/controller/, Create new file here, with any name it will be your controller.

Note : The name of Controller should be starts with Capital letter.



class Firstcontroller extends CI_Controller {

    public function __construct() {

    public function index() {
        echo "This is My Frist Controller";


While, working under MVC ,Open any file in browser you don’t need to call certain page, in place call the contraller, A controller has multiple methods and they act as an individual page.

In our case we can call our controller like following


Interaction with model and view

consider following case represents the student info.

Create Table

CREATE DATABASE `student_info`;
  `student_id` int(11) NOT NULL,
  `name` varchar(200) NOT NULL,
  `city` varchar(200) NOT NULL,
  `contact` varchar(100) NOT NULL,
   email varchar(200) NOT NULL
ALTER TABLE `student`
  MODIFY `student_id` int(11) NOT NULL AUTO_INCREMENT;


1.Create a model


class Student_model extends CI_Model {

    public function __construct() {

    public function get_all() {
        $sql = $this->db->get('students_table');

Note : Make sure the name of model and class should be same.

2.Create a controller


class Student_controller extends CI_Controller {

    public function __construct() {
        $this->load->model('student_model'); //load the model

    public function index() {
        $get_all = $this->student_model->get_all();
        $data = array(
            "page_title" => "Student List",
            "get_all" => $get_all
        //every key of $data array will be used as a variable in view
        $this->load->view("student_list", $data); //call view and pass the $data array

3.Create a view


        <title>Student List</title>
                    <th>Contact No</th>
                <?php foreach ($get_all as $key=>$val): //the array of student collection ?>
                <?php endforeach;?>

Some basic Instruction regarding CI

Use of .htaccess

execute ci on browser


to remove index.php from url you need to write following code in .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond $1 !^(client)
RewriteRule ^(.*)$ index.php?/$1 [L]

Use of autoload


In this file you can load helper functions, codeigniter built in libraries,database etc so that no longer need to load them individually in every page.

I hope you will find this post very useful regarding CodeIgniter. Let me know any questions if you have in comment regarding WordPress. I will reply you ASAP.


Looking for CODEIGNITER/PHP consultation?

CONTACT US for free consultation

Post by Alphanso Tech

Created in 2013, Alphanso Tech is a leading IT Consulting company with a presence in the USA, Canada, and India.We are a trusted and leading service provider to many top-tier companies in the area of Custom WordPress Development , Web Application Development , iOS App Development , Outsourcing Services, Online Marketing and many other related activities.

Leave a Reply

Your email address will not be published. Required fields are marked *