CodeIgniter interview questions and answers

CodeIgniter interview questions and answers

This section covers CodeIgniter interview questions and their best possible answers for freshers and experienced to help job seekers during technical interview.

1. What is CodeIgniter?

Ans: CodeIgniter is open source, web application framework for building websites using php which is loosely based on MVC pattern and which is most simple framework and easily learn. It is mostly known for it’s speed as compare to other frameworks in php.

2. When and who developed CodeIgniter?

Ans: The first public version of CodeIgniter was released on February 28, 2006.

3) What is the goal of CodeIgniter?

Ans: The goal is to enable you to develop projects with much faster than you could if you were writing code from scratch by providing a rich set of libraries for commonly needed tasks as well as a simple interface and logical structure to access these libraries.

4) What is current version of CodeIgniter?

Ans: CodeIgniter 3.0.6 is the current version of the framework as of April, 2016. CodeIgniter 2.2.6 is the legacy version of the framework.

Download the latest version of CodeIgniter.

5) What are the features of CodeIgniter?

Ans: Below is the list of features of CodeIgniter:

  • It is free to use as for open source framework.
  • It is light weight. The core system requires only a few very small libraries. Not like other frameworks that require heavy file libraries.
  • CodeIgniter is Fast. It is faster than any other framework in php.
  • The URLs generated by CodeIgniter are clean and search engine friendly. You will change any url to what ever you want from files.
  • CodeIgniter is Extensible. The system can be easily extended through the use of your own libraries, helpers, or through class extensions or system hooks.
  • CodeIgniter Uses MVC (Model View Controller) which allows great separation between logic and presentation.
  • CodeIgniter requires nearly zero configuration, does not require you to use the command line, not forced to learn a templating language.
  • Full Featured database classes with support for several platforms, Security and XSS Filtering, Error Logging.

6) Explain CodeIgniter File Structure.

Ans: When you download CodeIgniter you will see the following folder structure:


7) Explain Application Flow Chart in CodeIgniter.

Ans: The following graphic illustrates how data flows throughout the system:

app flow chart

  • The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
  • The Router examines the HTTP request to determine what should be done with it.
  • If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
  • Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
  • The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.
  • The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
You may like:  Learn Regular expressions in few hours

Read Also: CakePHP interview questions

8) Explain MVC in CodeIgniter.

Ans: Model–View–Controller (MVC) is an architecture that separates the representation of information from the user’s interaction with it.

Controller: The Controller serves as an intermediary between the Model, the View. controller mediates input, converting it to commands for the model or view.

Model: 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 model consists of application data and business rules.

View: The View is the information that is being presented to a user. A View will normally be a web page. A view can be any output representation of data.

9) Explain how you can enable CSRF (Cross Site Request Forgery) in CodeIgniter?

Ans: You can activate CSRF (Cross Site Request Forgery) protection in CodeIgniter by operating your application/config/config.php file and setting it to:

$config['csrf_protection'] = TRUE;

If you avail the form helper, the form_open() function will insert a hidden csrf field in your forms automatically.

10) Explain routing in CodeIgniter?

Ans: 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.

11) Explain what are hooks in CodeIgniter?

Ans: 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.

The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file:

$config['enable_hooks'] = TRUE;

Hooks are defined in application/config/hooks.php file.

For example:

$hook['pre_controller'] = array(
 'class'    => 'MyClass',
 'function' => 'Myfunction',
 'filename' => 'Myclass.php',
 'filepath' => 'hooks',
 'params'   => array('test', 'test1', 'webs')

12) How you will work with error handling in CodeIgniter?

Ans: CodeIgniter lets you build error reporting into your applications using the functions:

  • show_error(): This function will display the error message supplied to it using template application/errors/error_general.php.
  • show_404(): Function will display the 404 error message.
  • log_message(‘level’, ‘message’) :- This function lets you write messages to your log files. You must supply one of three “levels” in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the second parameter.
You may like:  5 Best WordPress Author Bio Plugins

13) Explain what helpers in CodeIgniter are and how you can load a helper file?

Ans: In CodeIgniter, helpers are group of function in a particular category that assist you to perform specific functions. In CodeIgniter, you will find many helpers like URL helpers- helping in creating links, Text helpers- perform various text formatting routines, Cookies- helpers set and read cookies.

You can load helper file by using command $this->load->helper (‘name’) ;

14) Explain how you will load or add a model in CodeIgniter?

Ans: Within your controller functions, models will typically be loaded.

You will use the function:

$this->load->model ('Model_Name');

15) Why is there a need to configure the URL routes?

Ans: 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.

16) List out different types of hook point in CodeIgniter?

Ans: Different types of hook point in CodeIgniter includes:

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

17) What are the helpers in CodeIgniter?

Ans: Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category. There are URL Helpers, that assist in creating links, there are Form Helpers that help you create form elements, Text Helpers perform various text formatting routines, Cookie Helpers set and read cookies, File Helpers help you deal with files etc.

Loading a helper file is quite simple using the following function:


18) Explain how you can prevent CodeIgniter from CSRF?

Ans: There are several ways to protect CodeIgniter from CSRF, one way of doing is to use a hidden field in each form on the website. This hidden field is referred as CSRF token. It is nothing but a random value that alters with each HTTP request sent. As soon as it is inserted in the website forms, it gets saved in the user’s session as well. So, when the form is submitted by the users, the website checks whether it is the same as the one saved in the session. If it is same then, the request is legitimate.

You may like:  10 Crucial Tips for Making Your Resume Stand Out from the Crowd

19) Mention what are the security parameter for XSS in CodeIgniter?

Ans: 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.

20) Explain how you can link images/CSS/JavaScript from a view in CodeIgniter?

Ans: In HTML, there is no CodeIgniter way, as such it is a PHP server side framework. Just use an absolute path to your resources to link images/CSS/JavaScript from a view in CodeIgniter


21) How you will use or add CodeIgniter libraries?

Ans: All of the available libraries are located in your system/libraries folder. In most cases, to use one of these classes involves initializing it within a controller using the following initialization function:

$this->load->library('class name');

22) Explain what is inhibitor in CodeIgniter?

Ans: For CodeIgniter, inhibitor is an error handler class, using the native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.

23) Explain how you can extend the class in CodeIgniter?

Ans: To extend the native input class in CodeIgniter, you have to build a file named application/core/MY_Input.php and declare your class with

Class MY_Input extends CI_Input {

24) Mention what is the default URL pattern used in CodeIgniter framework?

Ans: CodeIgniter framework URL has four main components in default URL pattern. First we have the server name and next we have the controller class name followed by controller function name and function parameters at the end. CodeIgniter can be accessed using the URL helper.

For example:

For any types of queries, you can contact us on

One thought on “CodeIgniter interview questions and answers”

Leave a Reply

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