Top 25+ CodeIgniter Interview Questions & Answers

Are you preparing for CodeIgniter job interview and wondering what questions you might be asked? In this blog we have hand-picked the questions you are likely to be asked in CodeIgniter job interview and provided to-the-point answers to each one of them so as to help you prepare better for CodeIgniter job interviews.

Always keep in the mind that, only academic knowledge is not enough to crack an interview. Employers expects from the candidate to have practical knowledge and hands-on experience as well. This CodeIgniter Interview Questions designed by industry expert will help you to gain practical knowledge of CodeIgniter.

1. Explain what is CodeIgniter?

CodeIgniter is an open source framework for web application. It is used to develop websites on PHP. It is loosely based on MVC pattern, and it is easy to use compare to other PHP framework.

2. What are the features of CodeIgniter?

a.) CodeIgniter is free to use, its an open source framework.

b.) Model-View-Controller Based System.

c.) Extremely Light Weight.

d.) Full Featured database classes with support for several platforms..

e.) CodeIgniter is Extensible.The system can be easily extended through the use of your own libraries, helpers, or through class extensions or system hooks.

f.) Excellent documentation.

g.) Full Featured database classes with support for several platforms,Security and XSS Filtering,Error Logging.


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

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

$config[‘enablehooks’] = TRUE;

4. List out different types of hook point in CodeIgniter?

Different types of hook point in Codeigniter includes


$hook[‘pre_controller’] = array(
‘class’ => ‘MyClass’,
‘function’ => ‘Myfunction’,
‘filename’ => ‘Myclass.php’,
‘filepath’ => ‘hooks’,
‘params’ => array(‘param1’, ‘param2’, ‘param3’)

5. Explain MVC in CodeIgniter?

CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

i. The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.

ii. The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page".

iii. The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.


6. Explain how you will load or add a model in CodeIgniter?

Within your controller functions, models will typically be loaded; you will use the function

$this->load->model (‘Model_Name’);

7. Explain what helpers in CodeIgniter are and how you can load a helper file?

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’) ;

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

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

Changing the URL routes has some benefits like :

a.) From SEO point of view, to make URL SEO friendly and get more user visits

b.) Hide some URL element such as a function name, controller name, etc. from the users for security reasons

c.) Provide different functionality to particular parts of a system

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

11. Explain how you can link images/CSS/JavaScript from a view in code igniter?

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




12. Explain what is inhibitor in CodeIgniter?

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.

13. Mention what is the default URL pattern used in CodeIgniter framework?

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


14. Explain how you can extend the class in CodeIgniter?

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 {



15. Explain how you can prevent CodeIgniter from CSRF?

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.

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

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

17. What is Stable version of CodeIgniter?

Version : 3.1.6,
Date : September 25, 2017
Url :

18. How to access config variable in CodeIgniter?

$this->config->item(‘variable name’);

19. How to unset session in CodeIgniter?


20. How do you get last insert id in CodeIgniter?


21. Explain CodeIgniter File Structure?

Following are the folder structure :-

  • Application

o cache
o Config
o Controllers
o core
o errors
o helpers
o hooks
o language
o libraries
o logs
o models
o thirdparty
o views

  • System

o core
o database
o fonts
o helpers
o language
o libraries

22. Explain Application Flow Chart in CodeIgniter?

The following graphic illustrates how data flows throughout the system:
CodeIgniter application flow :

1. The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
2. The Router examines the HTTP request to determine what should be done with it.
3. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
4. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
5. The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.


23. How you will use or add CodeIgniter libraries?

When we use the term “Libraries” we are normally referring to the classes that are located in the libraries directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create your own libraries within your application/libraries directory in order to maintain separation between your local resources and the global framework resources.

See more at

24. 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(‘message’ [, int $statuscode= 500 ] )

This function will display the error message supplied to it using template application/errors/errorgeneral.php.

show_404(‘page’ [, ‘logerror’])

This function will display the 404 error message supplied to it using template application/errors/error404.php.

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.

25. How to unset session in CodeIgniter?

We can use unsetuserdata to destroy particular session variable :


We can use sessdestroy to destroy all session:


26. How do you use aliases with autoloading models in CodeIgniter?

We can auto load model like this:

$autoload[‘model’] = array(array(‘usersmodel’, ‘users’), array(‘newsmodel’, ‘news’), ‘categorymodel’);

27. How to get random records in mysql using CodeIgniter?

We can use this:


28. How do you set default timezone in CodeIgniter?

We can do by adding

date_default_timezone_set(‘India/Banguluru’); in index.php

29. Who developed CodeIgniter?

CodeIgniter was developed by ellislab Inc.

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

31. How do I pass parameters to a controller’s index() function?

The obvious problem is that a second parameter on the URL will be interpreted as the method name. Short answer – use a URL like this:

/controller/index/param1/param2 Long answer – using _remap()

32. How do I do a COUNT(‘foo’) using the Active Record functions?

You need to use the SQL AS feature, where you assign a new name to a piece of data. For example:

$this->db->select(“COUNT(‘foo’) AS foo_count”, FALSE);// Run your query, and then use the

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

34. Helper vs. Library: CodeIgniter

Helpers are just small functions that help you avoid repetitive code and produce standard results.
Whereas libraries are contains classes, can include different files, talk to database etc.

A library is used in object oriented context (Controller, …), while a helper is more suitable to be used within the Views (non object oriented).


Helper, Plugin and Library :

Since, all three methods achieve the same ends. The question then is when do you use what? Fortunately, CI has also provided that distinction in their user guide which you can go read it yourself.

For me, these are my guidelines on when to use what:

Plugins – I put all 3rd party codes I’m using in my application as Plugins. I would, as best as I can, try to use classes rather than straight function calls.

Helpers – Any standalone straight functions calls, which are repetitive in nature, I classify them as Helpers. For example, sorting functions, my own calculation functions, etc

Libraries – I classify my own classes as ‘Libraries’. Normally, if I’m already writing a class in my application, it would then to be the core logic of the application, as such, I group them all in the Library folder.

Share This Post:

About The Author

Saurabh Samir - I have been helping aspirants to clear different competitive exams. LearnFrenzy as a team gave me an opportunity to do it on a larger level an reach out to more students. Do comment below if you have any questions or feedback's.