Top 50 CodeIgniter Interview Questions

Top 50 CodeIgniter Interview Questions

Top 50 CodeIgniter Interview Questions. A list of top frequently asked CodeIgniter interview questions and answers are given below.

1) What is CodeIgniter?
CodeIgniter is an open source and powerful framework used for developing web applications on PHP. It is loosely based on MVC pattern and similar to Cake PHP. It is very easy to use compare to other PHP frameworks.

2) 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.

3) Explain the folder structure of CodeIgniter.

If you download and unzip CodeIgniter, you will get the following file structure/folder structure:





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

5) Explain MVC in CodeIgniter.

CodeIgniter framework is based on MVC pattern. MVC is a software that gives you a separate logical view from the presentation view. Due to this, a web page contains minimal scripting.

6) Explain model in CodeIgniter.

Model’s responsibility is to handle all data logic and representation and load data in the views. It is stored in application/models folder.

7) How can you add or load a model in CodeIgniter?

To load models in controller functions, use the following function:


8) How can you connect models to a database manually?

To connect database manually use following syntax,


9) Explain views in CodeIgniter.

View folder contains all the markup files like header, footer, sidebar, etc. They can be reused by embedding them anywhere in controller file. They can’t called directly, they have to be loaded in the controller’s file.

10) How can you load a view in CodeIgniter?

View can’t be accessed directly. It is always loaded in the controller file. Following function is used to load a view page:


11) Explain controller in CodeIgniter.

A controller is the intermediary between models and views to process HTTP request and generates a web page. It is the center of every request on your web application.

12) What is default controller in CodeIgniter.

The file specified in default controller will be loaded by default when no file name is mentioned in the URL. By default, it is welcome.php which is the first page to be seen after installing CodeIgniter.

13) How will you call a constructor in CodeIgniter?

To use a constructor you need to mention the following line of code,


14) What is basic CodeIgniter URL structure?

Instead of using ‘query-string’ approach, it uses a segment based approach.

Its structure is as follows,

class represents controller class that needs to be invoked.

function is the method that is called.

ID is any additional segment that is passed to controllers.
15) What is inhibitor in CodeIgniter?

In CodeIgniter, Inhibitor is an error handler class that uses native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.
16) What is the default method name in CodeIgniter?

By default controller always calls index method. If you want to call a different method, then write it in the controller?s file and specify its name while calling the function.

17) Explain remapping method calls in CodeIgniter.

Second segment of URI determines which method is being called. If you want to override it, you can use _remap() method. The _remap method always get called even if URI is different. It overrides the URI.

18) What is helper in CodeIgniter? How can you load a helper file?

Helpers are the group of functions in a particular category that assist you to perform specific functions.

In CodeIgniter, there are many helpers like:

URL Helpers: helping in creating links.

Text Helpers: perform various text formatting routines.

Cookies Helpers: set and read cookies.

To load helper file, use the following command:


19) How can you load multiple helper files?

To load multiple helper files, specify them in an array,

array(‘helper1’, ‘helper2’, ‘helper3’)

20) Explain CodeIgniter library. How will you load it?

CodeIgniter provides a rich set of libraries. It is an essential part of CodeIgniter as it increases the developing speed of an application. It is located in the system/library.

It can be loaded as follows,


21) How can you create a library in CodeIgniter?

There are three methods to create a library,

Creating an entire new library
Extending native libraries
Replacing native libraries

22) Where a newly created library is stored in CodeIgniter structure?

It should be placed in application/libraries folder.

23) Can you extend native libraries in CodeIgniter?

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

24) 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.
25) What is routing in CodeIgniter?

Routing specifies the way how PHP files are served in CodeIgniter. It is different rather than accessing it directly from the browser. Routing facilitates you to customize the default URL pattern and use your own URL pattern according to the requirement. So, whenever there is a request made and matches your URL pattern it will automatically routed to the specified controller and function.

26) What is the need to configure URL routes?

URL routes are changed for some benefits:

From SEO point of view: It makes URL SEO friendly and get more user visits.

You can hide some URL element such as a function name, controller name, etc. from the users for security reasons.

It provides different functionality to particular parts of a system.
27) What are hooks in CodeIgniter?

Hook is a feature in CodeIgniter that provides a way to change inner working of the framework without hacking the core files. It facilitates you to execute a script with a particular path within the CodeIgniter. Usually, it is defined in application/config/hooks.php file.

28) How to enable CodeIgniter hook?

To enable hook, go to application/config/config.php/ file and set it TRUE as shown below,

$config[‘enable_hooks’] = TRUE;

29) What are different types of hook points in CodeIgniter?

A list of different types of hook points in CodeIgniter:


30) What are CodeIgniter drivers?

These are special type of library that has a parent class and many child classes. These child classes have access to the parent class, but not to their siblings. Drivers are found in system/libraries folder.

31) How to initialize a driver in CodeIgniter?

To initialize a driver, write the following syntax,


Here, class_name is the driver name.

32) How to create a driver in CodeIgniter?

To create a driver, there are three steps:

Making file structure
Making driver list
Making driver(s)

33) How to connect multiple databases in CodeIgniter?

To connect more than one database simultaneously, do the following,

$db1 = $this->load->database(‘group_one’, TRUE);
$db1 = $this->load->database(‘group_two’, TRUE);

34) How can you print SQL statement in CodeIgniter model?


35) What are CodeIgniter security methods?

CodeIgniter security methods help to create a secure application and process input data. The methods are given below:

XSS filtering
CSRF (Cross-site Request Forgery)
Class reference

36) What are the security parameters for XSS in CodeIgniter?

XSS stands for cross-site scripting. There are some cross-site scripting hack prevention filters in CodeIgniter. These filters either run automatically or manually, as per item basis to filter all POST and COOKIE data that came across. The XSS filters target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it finds any suspicious thing or anything disallowed is encountered, it converts the data to character entities.

XSS filtering uses xss_clean() method to filer data.

$data = $this->security->xss_clean($data);

37) How can you prevent CodeIgniter from CSRF (Cross Site Request Forgery)?

There are several ways to prevent CodeIgniter from CSRF.

Most used method is to use a hidden field in each form on the website. This hidden field is referred as CSRF token. It is 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 same as the one saved in the session. If it is same then, the request is valid.

38) How can you enable CSRF in CodeIgniter?

You can enable CSRF 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.

39) What is CSRF attack in CodeIgniter?

A CSRF attack forces a logged-on victim’s browser to send a forged HTTP request, including victim’s session cookie and other authentication information, to a web application.

40) What is token method in CSRF attack?

To protect from CSRF we need to connect both HTTP requests, form request and form submission. There are several ways to do this, but in CodeIgniter hidden field is used which is called CSRF token. The CSRF token is a random value that changes with every HTTP request sent.

Share Button

About admin

Leave a Reply

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


Author: pramod kumar kumawat Mob: 9269727062
Free WordPress Themes - Download High-quality Templates