CodeIgniter Interview Questions

Do you have an interview on Codeigniter to be attended? Are you unsure about how and where to start from? This blog will really be beneficial in boosting your confidence level. The Codeigniter Interview Questions and answers given in this blog will help you get acquainted with the nature of questions that could be asked in a Codeigniter Interview.

Codeigniter, an application development framework is mostly by developers who need a less complex toolkit to create interactive websites with all the features which users look for. Here are some Codeigniter Interview questions to understand the subject and take your confidence to the next level. The questions are sorted out according to the level of the candidates, i.e., the beginner's level and professional level.

Our team curated Codeigniter Interview Questions as follows: 

Codeigniter Interview Questions - Table Of Contents

Codeigniter Interview Questions - For Freshers

If you are new to this field, these are the fundamental questions mostly posed to freshers. Preparing these questions first will help you face the interview confidently.

1. What is Codeigniter?

Ans: Codeigniter is a programming framework for developing web applications on PHP. It is an open-source software framework and follows the model-view-controller (MVC) structure for web development. CodeIgniter contains a simple interface, libraries, a logical structure to access these libraries, helpers, plug-ins, and some other resources to help solve the complex functions of PHP, thereby improving the performance.

2. Which latest version of Codeigniter is currently in use?

Ans: The latest version of Codeigniter is 4.0, released on September 3, 2019.

3. How to find the version of the Codeigniter framework we are currently using?

Ans: Finding out the version can be done in two ways.

The first way is to run the below code:

<?php echo CI_VERSION;?>

The second way is to obtain the system/core/CodeIgniter.php directory and run the code given below:

define('CI_VERSION', '2.1.4');

4. What are the features provided by Codeigniter?

Ans: Codeigniter has the following features

  • It uses the MVC pattern for the development
  • It has MIT License with an open-source code.
  • It is the fastest framework for PHP.
  • It can support any database and platform.
  • Documentation in this is easy to use and read. 

5. What is the architecture of Codeigniter?

Ans: The architecture of Codeigniter has three essential points:

  • It is dynamically instantiated, making it incredibly lightweight.
  • The components in Codeigniter are independent, making it loosely coupled.
  • Every component has its singularity, as every class and function focuses on its purpose.

6. What is routing in Codeigniter, and why is it done?

Ans: The process of noting a URI endpoint and splitting it into parameters to know the information of the controller, module, and action of that controller should receive the request is called routing. Codeigniter has a one-to-one relationship between a URL string and its corresponding controller class/method. The segments pattern in the URL The routing rules in Codeigniter are defined in the appl-ication/config/routes.php file.

 MindMajix YouTube Channel

7. What are the various functions used in Codeigniter?

Ans: The functions in Codeigniter are globally defined and freely available. Loading of libraries or helpers is not required when using these functions.

set_status_header($code[, $text = ”])
remove_invisible_characters($str[, $url_encoded = TRUE])

8. How is the default timezone set in Codeigniter?

Ans: The default timezone in Codeigniter is set by opening the application using the config.php file and adding this code to it.

date_default_timezone_set('your timezone');

9. What is the procedure to add/link JavaScript/Images?CSS in Codeigniter?

Ans: To link or add the images/CSS/JavaScript in Codeigniter absolute path to your resources is used.

For example

// Refers to $config['base_url']
<img src="<?php echo site_url('images/myimage.jpg'); ?>" />

10. What is an inhibitor in Codeigniter?

Ans: An error handling class in Codeigniter is called an inhibitor. The inhibitor uses native functions of PHP's like register_shutdown_function, set_error_handler to handle parse errors, set_exception_handler, exceptions, and fatal errors.

11. What are the sessions in Codeigniter?

Ans: Sessions in CodeIgniter are the classes that help maintain a user's "state" and track their activity when they browse the website.

To use the session, the Session class is to be loaded in the controller.


sessions in Codeigniter use this method.


The Sessions library object will be available to use once the files are loaded:


12. How to extract the last inserted id in Codeigniter?

Ans: The DB Class insert_id() method is used in Codeigniter to get the last insert id.


function add_post($post_data){
$this->db->insert('posts', $post_data);
$insert_id = $this->db->insert_id();
return $insert_id;

13. What is CLI?

Ans: CLI is a text-based command-line interface that can interact with computers through a defined set of commands.

14. What is the use of CLI in Codeigniter?

Ans: CLI in Codeigniter is used for the following purposes

  • To run cron-jobs without using wget or curl.
  • To make cron-jobs inaccessible from being loaded in the URL by checking the return value of is_cli().
  • To make interactive "tasks" to perform tasks like run backups, set permissions, snip cache folders, etc.
  • CLI also helps in integrating Codeigniter with other applications in different languages. For example, a random C++ script could call a command and run code in models.

15. How to check the existence of a field or a column in any table in Codeigniter?

Ans: This code is used to check the presence of a field or a column in any table.

if ($this->db->field_exists('field_name', 'table_name'))
// some code...

16. What does the is_cli()method does in Codeigniter?

Ans: The is_cli() method in the Codeigniter checks if the request is originated from the command line or not.

It returns TRUE if the application is run through the command line and FALSE if not.

17. Codeigniter is known as a loosely based MVC Framework. Why?

Ans: Codeigniter is a loosely based MVC Framework as the controllers' classes such as models and views are not mandatory. We can even modify CodeIgniter to utilize HMVC also.

18. Explain ORM and list all the ORM in Codeigniter.

Ans: Object-relational mapping (ORM) is a programming technique to convert data from incompatible type systems using object-oriented programming languages. CodeIgniter Framework supports the following ORMs

  • Doctrine
  • DataMapper
  • Gas ORM

19. Where are the file routes defined in Codeigniter?

Ans: All the file routes in Codeigniter are defined in the application/config/routes.php file.

20. What are the commonly used URL helpers in Codeigniter?

Ans: URL helpers use a segment-based approach instead of the 'query-string' approach.

The URL structure is as follows,

  • Class represents the controller class that is to be invoked.
  • A function is a method that is called.
  • ID is an additional segment that is passed to controllers.

21. Where are the file routes defined in Codeigniter?

Ans: All Routing rules in Codeigniter are defined in the application/config/routes.php file.

22. How is the csrf token set in Codeigniter?

Ans: Csrf sets the protection in Codeigniter. To set csrf, the config value must be set to True.

Syntax: $config['csrf_protection'] = TRUE;

23. How and in which directory are the logs saved in Codeigniter?

Ans: All the logs in Codeigniter are by default stored in logs/ directory. To enable error logging, the "threshold" must be set for logging in application/config/config.php. The logs must be writable.

$config['log_threshold'] = 1;

Codeigniter Interview Questions - For Experienced

If you are an experienced candidate in this domain with experience of at least 2+ years, these are the most likely questions an interviewer possess. Preparing them will enhance your knowledge and confidence.

1. Describe the MVC structure used by Codeigniter.


  • MVC( model, view, controller) is a programming pattern that guides how developers design their applications to make website back-ends using CodeIgniter.
    This pattern allows for minimal scripting and a firm, logical overview of the application for separating the logic from its presentation.
  • Model: The model includes all of the data structures linked directly to a specific database. It also contains functions to retrieve, save, and manipulate the data from the database.
  • View: The View is responsible for everything visible to the user. In CodeIgniter, a view also includes entities like headers and footers.
  • Controller: The controller is the 'puppet master' in Codeigniter that manages the seamless integration of models and views and act as an intermediate, taking care of any other resources that need to process HTTP requests. 

2. Describe a Codeigniter' model' in detail.

Ans: Models are PHP classes that define how the application interacts with the database. Like other classes, models contain functions that retrieve, store, insert, and change the database's information. These functions are stored in the application/models folder.

3. List the databases supported by Codeigniter Frameworks.

Ans: The databases supported by Codeigniter Frameworks are:

  • MySQL (5.1+) via the MySQL (deprecated), MySQL and PDO drivers
  • Oracle via the oci8 and PDO drivers
  • PostgreSQL via the Postgre and PDO drivers
  • MS SQL via the MsSQL, Sqlsrv (version 2005 and above only) and PDO drivers
  • SQLite via the SQLite (version 2), sqlite3 (version 3) and PDO drivers
  • CUBRID via the Cubridand PDO drivers
  • Interbase/Firebird via the iBase and PDO drivers
  • ODBC via the ODBC and PDO drivers

4. What is a helper file in Codeigniter, And How to load the helper file?

Ans: Helper files help the users with tasks. These files are a collection of simple, procedural functions in a particular category. Each helper function performs one specific task independently.

The helper files are not loaded automatically and have to be manually loaded. Once loaded, it is available in the controller and views.

Helpers are stored in the application/helpers directory.

The helper file is loaded using the following method:


Here, name is the helper file name without the .php file extension or the "helper" part.

5. What are the various hooks used in Codeigniter?

Ans: Codeigniter's hooks provide a way to modify the framework's functionality without disturbing the core files.

These are the hook points available in Codeigniter:

  • pre_system - It is called during system execution.
  • pre_controller - This is called immediately before calling the controllers.
  • post_controller - constructor - This method is called instantly after the controller is instantiated but before calling any method.
  • post_controller - The post_controller hook is called immediately after the controller is fully executed.
  • display_override - This hook overrides the _display() method.
  • cache_override - This hook is used when there is a need to call our method instead of the method from Output Library called _display_cache(). It permits us to use your own cache display mechanism.
  • post_system - This hook is called when the final page is sent to the browser after the final execution.

6. How is a model added/loaded in Codeigniter?

Ans: Models in Codeigniter are loaded and called from within the controller methods. A model is loaded using the following code:

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

The particular path from the model's directory is included when a model is present in a sub-directory. For example, if the model is located at application/models/blog/Posts.php, it is loaded using:

$this->load-> model('blog/Posts');

Once a model is loaded, its methods are accessed using an object with the same name as the controller:

class Blog_controller extends CI_Controller {
public function blog()
$data['query'] = $this->blog->get_last_ten_entries();
$this->load->view('blog', $data);

7. How to load or use Codeigniter libraries?

Ans: $this->load->library(‘library_name’); method is used to load a library in CodeIgniter.

//Loading Cart library
Using Cart library methods
$data = array(
'id' => 'sku_9788C',
'qty' => 1,
'price' => 35.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')

8. What is the procedure to run 301 redirects in Codeigniter?

Ans: A redirect helper is used in Codeigniter for 301 redirects.
Syntax :

redirect($uri = '', $method = 'auto', $code = NULL)
$uri (string) – URI string
$method (string) – Redirect method (‘auto’, ‘location’ or ‘refresh’)
$code (string) – HTTP Response code (usually 302 or 303)
Return type: void
Sample Usage:-
redirect('/posts/13', 'New location', 301);

9. Describe the flowchart of the Codeigniter application?

Ans: This image shows how data flows through the Codeigniter system.

  • The index.php acts as the front controller that loads the base
    resources that are required to run CodeIgniter.
  • The Router examines the HTTP request and decides what is needed to be done.
    If a cache file exists, it is sent directly to the browser, bypassing  
    the normal system execution.
  • Security: The HTTP request and any data submitted by the users are screened for security before any application controller is loaded.
    The controller loads the model, helpers, core libraries, and any
    other resources that are needed to process the request.
    The finalized View, when designed, is sent to the web browser for the final check. If caching is enabled, the ViewView is cached first to serve on specific requests.

10. How are config variables set or get in Codeigniter?

Ans: All config variables in Codeigniter are stored and located at the “application/config/config.php” file.

The following code is used in Codeigniter to set or get a config variable

// Setting a config variable dynamically
$this->config->set_item('variable_name', value);
// Getting value of config variable in Codeigniter.

11. How is a record deleted in Codeigniter?

Ans: The delete function is used to delete one or more row data from a table in Codeigniter.

//DELETE FROM table WHERE id = $id
$conditions =['id' => $id]
$this->db->delete('table_name', $conditions); 
// Deleting records from more than one tables in one single go
$tables = array('table1', 'table2', 'table3');
$this->db->where('id', $id);

12. How are the validations implemented in Codeigniter?

Ans: Validations in Codeigniter are implemented using a form_validation library. The simple server-side validation code in Codeigniter is:

/* Load form validation library */ 
/* Set validation rule for name field in the form */ 
$this->form_validation->set_rules('firstname', 'FirstName', 'required'); 
if ($this->form_validation->run() == FALSE) { 
else { 

13. How many types of messages can be logged in Codeigniter?

Ans: Three message types are logged in Codeigniter. They are :

  • Error Messages: These messages are actual errors, such as PHP or user errors.
  • Debug Messages: These messages assist in debugging. For example, the debugging info is logged when a class is initialized.
  • Informational Messages: These are the messages of least priority that give information about the process.

14. How does the Codeigniter generate raw queries?

Ans: To generate the raw queries the below method is used


The difference between get_compiled_select() and last_query() is that get_compiled_select() gives the query string which is generated even if the query is not run against the database.

15. What are the ways to use $config variables in view files?

Ans: To use the $config variables into the view the following ways are used. 
The variables are passed through the controller using load->view()

With $this->config->item()
With function config_item()

16. How do you remove index.php from the URL in Codeigniter?

Ans: To remove the index.php from URL in Codeigniter the following steps are used
Step 1: Open config.php and replaces

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


$config['uri_protocol'] ="AUTO" to $config['uri_protocol'] = "REQUEST_URI"

Step 2: Change your .htaccess file to

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


Here in this blog, almost all of the topics related to Codeigniter are covered to help you get yourself prepared. And these Codeigniter Interview Questions can come to your aid when attending an interview. Prepare well until you feel confident. All the best!

Course Schedule
JavaScript TrainingJun 22 to Jul 07View Details
JavaScript TrainingJun 25 to Jul 10View Details
JavaScript TrainingJun 29 to Jul 14View Details
JavaScript TrainingJul 02 to Jul 17View Details
Last updated: 03 Jan 2024
About Author


Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .

read less