Learn CodeIgniter Step by Step

Welcome back, Developer! Today I want to share some basic and advanced concepts of the PHP framework that is very helpful for developers.

As a concept, PHP is an open source development technology that was invented in 1993 by Rasmus Lerdorf.

PHP has different framework technologies. In these posts, I want to share the CodeIgniter PHP framework.

I mostly focused on the following Topics

  1. What is CodeIgniter
  2. Pre-requirement for CodeIgniter
  3. How to Download
  4. How To Install and Configure
  5. How to Create a Database
  6. What is MVC On CodeIgniter
  7. How to Create a Controller
  8. How to Create a Model
  9. How to Create View
  10. How to Run CodeIgniter Project

1. What is CodeIgniter

CodeIgniter is a PHP framework that is used to develop simple and complex projects in a short period.

By Using CodeIgniter we can develop E-commerce, Personal websites, large systems, ERP projects, content management systems, and many others.

CodeIgniter is an elegant PHP framework, It has very clear documentation, very clear user manual, and is full of stack-over guides.

CodeIgniter is a very lightweight framework. The learning curve of CodeIgniter is very short when compared to other PHP frameworks.

2. Pre-requirement for CodeIgniter

To start learning CodeIgniter your computer must have the following setups

  1. Local server XAMPP or WAMP
  2. PHP
  3. Code Editors / VScode or Sublime and others

Some basic concepts about PHP, HTML, CSS, and Bootstrap front-end developments

How to Download CodeIgniter Setup

Downloading the CodeIgniter setup is a very easy step. To download codeigniter we can search on Google download codeigniter and select the first link that Google provides.

After clicking the first link then you can download CodeIgniter setups. Select the current version of the link and download it.

How to Install and Configure CodeIgniter

Installing of Codeigniter is straightforward. To Install CodeIgniter PHP setups we must start local servers on your computers or remote servers.

For this training, we use the XAMPP local server to run Codeigniter setups.

After starting Xampp server. Then go to the download folder extract your downloaded codeigniter setups copy it to the local server xampp/htdocs/ and paste on here.

After pasting your extracted folder of codeigniter setups and rename to your project name.

eg. if Extracted folders abcdefr then change it to your project name. employee record management system(terms).

To run CodeIgniter Project open your browser and type localhost/your project name

localhost/erms // means employee record management system

How Configure CodeIgniter

Configuration in codeigniter simple and It takes less than one minute process. There are three type of configure in codeigniter

  1. Site ULR configuration
  2. Autoload Configuration
  3. Database configuration

1. Site URL Configuration

site URL configuration is the process of configuring your site to local or remote servers.

To configure url for your system we must open PHP file that found in config folder and config.php and edit line 26 from

$config['base_url'] = ''; to $config['base_url'] = 'http://localhost/erms';

In site configuration we can also change default language of the system.

$config[‘language’] = ‘english’; change it to your local language

Rember: By CodeIgniter we can create multi langual project.

2. Auto load Configuration

In Auto load configuration we configure when our system start our auto load configuration also start. Auto load configuration include Packages,Libraries, Driversand , Helper files, Language files and Models.

To configure auto load we must open config folder and open autoload.php and edit it to the following codes.

The most important things in auto load configurations are as follow

Libraries Configuration

 $autoload['libraries'] = array('database', 'email', 'session');

Auto-load Helper Files

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

The above two configuration is the most common configuration at all.

with out the above two configuration we can not do any things.

As general Libray and Helper configuration the most basic configuration.

3. Database configuration

Database configuration is the process of configuring database with our project. To configure our system to system we must follow the following steps.

Step 1: Open your project with your code editor

step 2: Select config folder and open database.php file in config folder and edit the following code below.

$db['default'] = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'root',// your server username
	'password' => '', // your server password
	'database' => 'erms_db',// Your system database
	'dbdriver' => 'mysqli',// Your database enginee
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE

The above configuration it database configurations

How to Create a Database

Database is the storage of electronic data in the form of row and columns. Database concept is the most and common concept in development technology. With out knowing the concept of database we can not do any thing in software developement process.

In Codeigniter database is the crusual thing. To create database we must follow the following things.

  1. Run your local or remote server and start MySQL and apache servers.
  2. Open phpmyadmin on your browsers.

3. Create new Database and name it erms_db

4. configure it with our codeigniter projects.

Remember: Creating new tables also similar to the above steps.

What is MVC On CodeIgniter

MVC means Model View Controller pattern.

M: Model -is the place where our business logic is creating

  • We can type active query recording.
  • we can also write basic and advanced concepts on models based on database concepts

V: View

  • the presentation layer of the system
  • view is generally the front end of our project
  • We can use any front-end technologies
  • for this training, we use Bootstrap technology for the front end.

C: Controller: The controller is the middle man of the model and views

with out controller our system can not run. That means the controller is the basic and main functions.

  • It gives the pass where our system goes.
  • It also controls how to manage our system.
  • To run a condeigniter project we must call one of the controller names and call it functions or methods.

Generally to run our project we must know MVC pattern concepts.

How to Create a Controller

Creating a controller is a very easy way.

To create a controller in codeigniter we must follow the following steps.

Step 1: Open your project by the Code editor that you have.

Step 2: Select Controller folders

Step 3: Create a new PHP Class that extends CI_Controllers

defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller


On the above code we create Home Controller that extends CI_Controller.

How to creat Function or Methods on Contoller

Controller is the composed of different function that work for specific things. That means Home controller have different function that work for home controller to perform what customer or client need. Creating Controller only does not meet any goals.

Create function index on home controller as follow

defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller
public function index(){

the above code shows how to create index function on controller and load view on it.

How to Create a Model

Model is the business logic where we write. In the model, we write all about active query codes. The active query also includes the CRUD Operation of the system.

Creating a model in Codeigniter is similar to creating of Controller, but the difference Models extends CI_Model and Controller extends CI_Controllers.

To create a Model follow the following steps

  1. Open your project by code editors
  2. Choose Models folders
  3. Add a new PHP class that extends CI_Model

class Home extends CI_Model
    public function getAll(){
        return $this->db->get('table_name')->result();

The above code shows how to create the model and create a function that selects all data from your table names

How to Create View

The view is user interface design concepts. In view, we create the layout of the system. The most clear layout system the most user-friendly system.

To create view in Codeigniter must follow these steps.

Step 1: select view folder and create new file

Step 2: create new welcome.php

Step 3: Write HTML or any other front-end technology.

        <title>welcome to CodeIgntier Tutorials</title>
        <h3>This is CodeIgntier Tutorials on bbn11</h3>

Author: bbnadmin

2 thoughts on “Learn CodeIgniter Step by Step

Leave a Reply

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