Top 20 CodeIgniter Interview Questions and Answers

Top 20 CodeIgniter Interview Questions and Answers

Top 20 CodeIgniter Interview Questions and Answers

Codeigniter is fast, reliable, lightweight and more capable, built with performance in mind.
PHP framework is an easy debug that allows you easily to get out the errors in your development

A Quick Overview of CodeIgniter
What is Codeigniter? CodeIgniter is open source & powerful framework used for developing web applications on PHP. It is based on MVC(Model, View, Controller) 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
Official Website

1.What Are The Most Prominent Features Of Codeigniter?

A list of most prominent features of CodeIgniter:

  • It is an open source framework and free to use.
  • It is extremely light weighted.
  • It is based on Model View Controller (MVC) pattern.
  • It has full featured database classes and support for several platforms.
  • It is extensible. You can easily extend system by using your own libraries, helpers etc.
  • Excellent documentation.

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

CodeIgniter is a PHP framework that uses a Model View Controller (MVC) architecture with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

3.Explain Codeigniter Architecture?

From technical point of view, CodeIgniter is dynamically instantiation (light-weighted), loosely coupled (components rely very less on each other) and has component singularity (each class and functions are narrowly focused towards their purpose).

You may Like

Best 50 php Interview question for Php developer in 2020

4.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

5.Explain what are hooks in CodeIgniter?

Codeigniter’s hooks feature provides a way to change the inner working of the framework without hacking the core files. In other word, hooks allow you to execute a script with a particular path within the Codeigniter.  Usually, it is defined in application/config/hooks.php file.

6.Explain routing in Codeigniter?

In CodeIgniter, the way PHP files served is different rather than accessing it directly from the browser. This process is called routing. Routing in CodeIgniter gives you freedom to customize the default URL pattern to use our own URL pattern according to the requirement. So, whenever there is a request made and matches our URL pattern it will automatically direct to the specified controller and  function.

7. Why is there a need to configure the URL routes?

Changing the URL routes has some benefits like

  • From SEO point of view, to make URL SEO friendly and get more user visits
  • Hide some URL element such as a function name, controller name, etc. from the users for security reasons
  • Provide different functionality to particular parts of a system

8.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';
9.Explain the basic Url Structure in Codeigniter?

The basic URL structure is

  1. The first segment represents the controller class that should be invoked.
  2. The second segment represents the class function, or method, that should be called.
  3. The third, and any additional segments, represent the ID and any variables that will be passed to the controller.

your URLs can be remapped using the URI Routing feature for more flexibility

10.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.

Difference between Helper and Library in CodeIgniter is that the Helper is a file with a set of functions in a particular category, while the Library is a class with a set of functions that allows creating an instance of that class

11.What do you mean by routing in Codeigniter?

URL routing is a technique through which it converts SEO friendly URLs into a server code format that understands it easily and drives a request to corresponding handler scripts.

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 rules are defined in routes.php file at the location application/config. In this file you’ll see $route array, it permits you to specify your own routing criteria. Routes can be classified in two ways, either using Wildcards or Regular Expressions.

There are two types of wild cards

  • :num−series containing only numbers will be matched.
  • :any−series containing only characters will be matched.


$route['product/:num'] = 'catalog/product_lookup/1';

URL containing first segment as ‘product’ and second segment as any ‘number’ will represent to the URL containing ‘catalog’ class and ‘product_lookup’ method passing in the match as the variable to the function

12.How to remove index.php from URL in Codeigniter?

We need just two step  to remove Index.php from url  in codeigniter

1. We need to do is open our config file and make you change

$config['index_page'] = "index.php" to $config['index_page'] = "";

2 We need to create .htaccess  file and put in root folder


RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

13.What is CSRF and how you can enable CSRF in CodeIgniter?

CSRF stands for cross-site request forgery

In codeIgniter The CSRF token can be regenerated every time for submission or you can also keep it the same throughout the life of the CSRF cookie.

We can enable CSRF protection by altering your application/config/config.php file in the following way:

$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.

14.What Are The Security Parameter For Xss In Codeigniter?

Codeigniter has got a cross-site scripting hack prevention filter. This filter either runs automatically or you can run it as per item basis, to filter all POST and COOKIE data that come across. The XSS filter will target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it detects any suspicious thing or anything disallowed is encountered, it will convert the data to character entities.

15. Why Codeigniter Is Called As Loosely Based Mvc Framework?

Reason behind this is we does not need to follow strict MVC pattern while creating application.We can also able to build with model only view and controllers are enough to built a application.


16.How You Will Work With Error Handling In Codeigniter?
CodeIgniter lets you build error reporting into your applications using the functions described below. In addition, it has an error logging class that permits error and debugging messages to be saved as text files.

  • show_error() function displays errors in HTML format at the top of the screen.
Syntax show_error($message, $status_code, $heading = ‘An Error Was Encountered’)
  • $message (mixed) − Error message
  • $status_code (int) − HTTP Response status code
  • $heading (string) − Error page heading
Return Type mixed
  • show_404() function displays error if you are trying to access a page which does not exist.
Syntax show_404($page = ”, $log_error = TRUE)
  • $page (string) – URI string
  • $log_error (bool) – Whether to log the error
Return Type void
  • log_message() function is used to write log messages. This is useful when you want to write custom messages.
Syntax log_message($level, $message, $php_error = FALSE)
  • $level (string) − Log level: ‘error’, ‘debug’ or ‘info’
  • $message (string) − Message to log
  • $php_error (bool) − Whether we’re logging a native PHP error message
Return Type void

Logging can be enabled in application/config/config.php file. Given below is the screenshot of config.php file, where you can set threshold value.

17.How Can You Extend Class In Codeigniter?

You have to build a file name application/core/MY_Input.php and declare your class with Class MY_Input extends CI_Input {}to extend the native input class in CodeIgniter

18.Can You Extend Native Libraries In Codeigniter?

Yes, we can add some extended functionality to a native library by adding one or two methods.

19.How To Unset Session In Codeigniter?



 20.How to install CodeIgniter? Explain step by step.

CodeIgniter can be installed with simple  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

21.How we can print SQL statement in codeigniter model?
We can use $this->db->last_query(); to display the query string.
we can use print_r($query); to display the query result.

Please share these Top 20 CodeIgniter Interview Questions and Answers  for you friend , this may help for them

Written By


Comments :

Leave a Reply