CodeIgniter Interview Questions and Answers

06 Feb 2023, 40 Questions

CodeIgniter is a PHP open-source web development framework for building dynamic websites. Based on the MVC development pattern, Codeigniter can be modified to use the HMVC pattern. This pattern allows developers to maintain controller, view, and models in a sub-directory format. This framework is known for its higher speed as compared to other PHP frameworks. If you are looking for Codeigniter interview questions, we can help you!

A Quick Overview of CodeIgniter
What is Codeigniter? It is a PHP open-source web development framework for building dynamic websites. Based on the MVC development pattern, Codeigniter can be modified to use the HMVC pattern.
Latest Version 4.0, released on September 3, 2019
Stable Version 3.1.10, released on January 16, 2019
Created By EllisLab
Written in PHP
License MIT License

Most Frequently Asked CodeIgniter Interview Questions

Here in this article, we will be listing frequently asked CodeIgniter Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q1. What is Codeigniter & why it is used for?

It is a PHP open-source web development framework which is used for building dynamic websites.

69 5
Q2. What is the latest version of Codelgniter? Lists its new features.

4.0 is the latest version of the Codelgniter framework. This version is released on September 3, 2019.

Here are some new features that support Codelgniter

  • URL Helper
  • Query builder
  • Email Library
  • Form Validation Library
  • Session Library

Codelgniter updated these modules to enhance features.

32 1
Q3. List the databases supported by Codeigniter?

Currently Codeigniter supports these databases that's are given below :-

  • MySQL
  • Oracle
  • PostgreSQL
  • SQLite
  • ODBC
  • Firebird etc
23 7
Q4. What is hooks and how we can configure hooks in CodeIgniter?

It is a type of events which can be called before and after the execution of a program in CodeIgniter. For example Hooks can be used where we need to check whether a user is logged in or logged out before the execution of controller.

It can be globally enabled or disabled by setting in the application/config/config.php page

It can be defined in application/config/hooks.php page. In CodeIgniter each hook is specified like an array with this prototype:

20 7
Q5. How to add or load a model in CodeIgniter?

You can do it with this $this->load->model("ModelName");

20 2
Q6. How to load a view in CodeIgniter?

You can use this $this->load->view('name'); to load a view in CodeIgniter.

11 4
Q7. What is the default controller used in CodeIgniter? How we can change it?

In CodeIgniter when a specified file in the default controller loaded by default when there is no file name mentioned in URL. By default "welcome.php" file is loaded after installing CodeIgniter.

Yes, we can change it from application/config/routes.php. We have to pass our controller name which we want to load by default in $route['default_controller']

For example, now the frontend is the default controller $route['default_controller'] = 'Frontend'; from now. Interview questions on Codeigniter are always a level up and thus a little tough to crack.

8 2
Q8. Explain the basic Url Structure in Codeigniter?

The basic URL structure is

Here class represents controller's class that needs to be invoked.
Here "function" is name of method which is called.
ID is an additional parameter that is passed to controllers.

12 0
Q9. What do you mean by helper in CodeIgniter?

Helpers is collection of functions which help us with different tasks as name suggested. Every helper function is used to performs specific task with no dependence on other functions.

CodeIgniter provide various types of helper class like url_helper, captcha_helper ,email_helper. All these helpers are located in system/helper.

By default CodeIgniter does not load any Helper files. First step is to be load Helper. After loaded it is available in all controller and views.


How we can load a Helper : $this->load->helper('name');
Here "name" is file name of helper.

How to load multiple Helpers at one time.
$this->load->helper(array('helper1', 'helper2', 'helper3')); // Here helper1,helper2,helper3 are different helper's name.

7 2
Q10. Explain the difference between helper and library in CodeIgniter?

Helper is a set of Common functions which we can use within Models, Views, Controllers everywhere. Once we include that file then we can get access to the functions.
Library is a class which we need to make an instance of the class by $this->load->library() this function.

NOTE : A library is used in object-oriented context but a helper is more suitable to be used within the Views

9 0
Q11. What do you mean by Get_instance in CodeIgniter?

It is a globally available methods or functions that returns the Controller super-object which contains all the currently loaded classes. get_instance() function  returns the Controller class instance.

8 4
Q12. What do you mean by routing in Codeigniter?

It is the process of taking a URI endpoint and decomposing it into parameters to determine module controller and action of that controller should receive the request.


CodeIgniter has a userfriendly URI routing rule so that we can re-route URL easily . There is a one-to-one relationship between a URL string and its corresponding controller class and its methods.


Routing is a technique through which we can converts SEO friendly URLs into a server code format that easily understandable.


We can manage these from routes.php file at the located in application/config.

4 1
Q13. List some different hook point in Codeigniter?

Codeigniter supports various hook points.

  • post_controller_constructor
  • pre_controller
  • post_sytem
  • pre_system
  • cache_override
  • display_override
  • post_controller

If you are scrolling on the web for Codeigniter interview questions for 2 year experience pdf, then this guide will gonna help you.

7 2
Q15. What do you mean by inhibitor in CodeIgniter?

Inhibitor is an error handling class. It is using the native PHP functions like set_error_handler, set_exception_handler, register_shutdown_function to handle all error's like parse errors, exceptions, and fatal errors.

3 4
Q16. How to remove index.php from URL in Codeigniter?

You can follow these given steps to remove index.php from URL in Codeigniter.

  • Please open config.php and change from $config['index_page'] = "index.php" to $config['index_page'] = "";
  • Update also from $config['uri_protocol'] ="AUTO"; to $config['uri_protocol'] = "REQUEST_URI";
  • Put this code in your htaccess file
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
9 1
Q17. What is CSRF and how you can enable CSRF in CodeIgniter?

In codeIgniter CSRF token is a random generated value that changes with each HTTP request sent by webform. When the form is submitted by user then website checks this submitted CSRF token equals or not the saved in the session.

We can enable CSRF protection from config.php and update the following values

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name'; //The token name
$config['csrf_cookie_name'] = 'csrf_cookie_name'; //The cookie name
$config['csrf_expire'] = 7200; // It will expire after this given time.

6 1
Q18. How to extend the class in Codeigniter?

You have to build a file with name application/core/Blog.php and declare your class with

Class Blog extends CI_Input {
      // Write your code here

4 1
Q19. What is Codeigniter Library and how we can load it?

Codeigniter provides a rich set of libraries, which indirectly increase the speed of developing an application. These Codeigniter system library is located in system/libraries.

In Codeigniter the library can be loaded with $this->load->library('class name');

If we want to load multiple libraries then we can use like $this->load->library(array('comment', 'blog'));

4 0
Q20. How to handle sessions in Codeigniter?
How to add values in session in Codeigniter

$_SESSION['username'] = '' // It can be use in core PHP
$this->session->set_userdata('username', ''); // It can be done in Codeigniter

We can pass array to store values in session in Codeigniter.

$array = array(
    'username' => '',
    'email' => '[email protected]',
    'url' => ''


How to remove values in session in Codeigniter

unset($_SESSION['username']); // It can be use in core PHP
$this->session->unset_userdata('username'); // It can be done in Codeigniter

If we want to remove more values from session then we can use like this

$this->session->unset_userdata($array);  // $array is defined above. It is an array with key & values.

How to get data from session in Codeigniter

$this->session->userdata('username'); // Here we will get username, if it is exists in session.

7 1
Q21. Explain why codeigniter is called as loosely based mvc framework?

It is called as loosely based mvc framework because in codeigniter controller is the necessary but model and view are optional. It means we can build a website without model.

6 0
Q22. How to install CodeIgniter? Explain step by step.

CodeIgniter can be installed with four steps that are given below:

  • Download it from its download page & then unzip the package.
  • Upload its files and folders on your server or localhost.
  • Open application/config/config.php file and set base URL.
  • If you want to use database then open application/config/database.php file and set your database credientails.
  • Now it's installed

If you want to configure additional setting then you can click here

2 1
Q23. What are the server requirements to install codeigniter?

We need only PHP version 5.6 or greater than 5.6. because of potential security and performance issues.

2 0
Q24. How we can load multiple helper files in Codelgniter?

You have to pass your helpers in array form. Here helper_1, helper_2, helper_3, helper_4 are different helpers that we want to load.

    array('helper_1', 'helper_2', 'helper_3', 'helper_4')

1 0
Q25. How we can enable hooks in CodeIgniter?

If you want to enable hooks then you have to enabled/disabled by setting in the application/config/config.php file.

If you want to enable hooks then use this $config['enable_hooks'] = TRUE;

1 0
Q26. What do you mean by drivers and how we can create in CodeIgniter?

In CodeIgniter drivers are a very special type of Library that has a parent class and its child classes. Child classes have the access to its parent class but not their siblings. It provides an elegant syntax in your controllers file for libraries.

It can found in the system/libraries/ directory.

If we want to use a driver we have to initialize it within a controller with this given method.

Here class_name is the name of the driver class which we want to invoke.

How we can create our own drivers in CodeIgniter.
  • You can create your own driver folder in /application/libraries/
  • Create your_Your_Driver_name.php file in /application/libraries/Your_Driver
  • In /application/libraries/Your_Driver/drivers
    • Your_Driver_name_subclass_1.php
    • Your_Driver_name_subclass_2.php
2 0
Q27. How we can print SQL statement in codeigniter model?

You can use $this->db->last_query(); to display the query string.
You can use print_r($query); to display the query result.

2 0
Q28. Explain how to create custom 404 page in CodeIgniter?

You can create your custom 404 page with these steps. Please follow these steps one by one.


  • You have to update your own created controller's class with $route['404_override'] = 'Controller_Class_Name';. You have to update this in your application/config/routes.php
  • Please create your new controller "Controller_Class_Name" file in your controllers directory application/controllers/.
  • Please put this code in your Controller_Class_Name.php

    class Controller_Class_Name extends CI_Controller {
         public function __construct() {

        public function index() {
  • Now create your "error_page_404" view file.
5 0
Q29. How to insert data into database in codeigniter?

You can use $this->db->insert(); to insert data in your database in Codeigniter.


If you want to insert this in your "Admin Table".

$dataArray = array(
       'email'=>'[email protected]'


// Here "Admin" is My TableName

1 0
Q30. How to get last inserted id in codeigniter?

You can use $lastInsertID = $this->db->insert_id(); after insert query.

2 0
Q31. How to write join query in CodeIgniter?

$this->db->join('blog', 'comment.blog_id=', 'inner');


$this->db->join('blog', 'comment.blog_id=');

1 1
Q32. Explain how to set and get config item value in Codeigniter?

To set config value $this->config->set_item('mainURL',''); we can use this.

To get config value $this->config->set_item('mainURL'); we can use this.

0 0
Q33. How we can get Ip address in Codeigniter?

You can use $this->input->ip_address(); this to get IP Address.

3 1
Q34. How we can get current method or controller in Codeigniter?

You can use this $this->router->fetch_class(); to get current controller name.
You can use this $this->router->fetch_method(); to get current method.

2 0
Q36. How to use delete query in Codeigniter?

You can use $this->db->delete('admin', array('id' => 5)); this query to delete record according to condition
// DELETE FROM admin WHERE id = 5

2 0
Q37. How to truncate table with query in Codelgniter?

// TRUNCATE table admin;
You can use this to truncate table
$this->db->from('admin'); // select admin table
$this->db->truncate(); // truncate admin table


You can also use like this
$this->db->truncate('admin'); // truncate admin table

4 0
Q38. How to enable error log in CodeIgniter?

Step 1. Make /application/logs log folder writable
Step 2. Set $config['log_threshold'] = 1; in /application/config/config.php

5 0
Q39. How we can redirect a page in CodeIgniter?

We can use the redirect() function to redirect on any page.


$this->load->helper('url');       // Firstly you have to load url helper.
if (condition != TRUE) {

2 1
Q40. How we can connect multiple databases in CodeIgniter?

$database1 = $this->load->database('DB1', TRUE); // Connect with database 1
$database2 = $this->load->database('DB2', TRUE); // Connect with database 2

2 0

History of Codeigniter

The first version was released in Feb 2006 by EllisLab.

Advantages of Codeigniter

If you are preparing for Codeigniter interview questions, do memorize the powers of CodeIgniter.

  • Easy to learn, handle and customize
  • Flexible and easy to configure
  • Amazing Active Record Implementation
  • Best-in-class documentation
  • Discount, Offers, Coupons and Options and Properties
  • Extensive user base
About Best Interview Question
Best Interview Question
Technical Consultant

With our 10+ experience in PHP, MySQL, React, Python & more our technical consulting firm has received the privilege of working with top projects, 100 and still counting. Our team of 25+ is skilled in distinct programming languages such as Python, Java, React.js, Angular, Node.js, PHP, HTML, CSS, Designing, iOS and Android apps, Database, .net, QA, Digital Marketing and Govt. jobs, etc. We are helping 10+ companies in solving their technical problems. When not found coding, our technical consultants can be seen helping out others.