CodeIgniter Interview Questions

CodeIgniter Interview Questions

Sharing Latest 35+ Codeigniter Interview questions and their answers that asked by an interviewer in Codeigniter interviews. Read about helpers, sessions, hooks, Routing, Constants ORM supported by Codeigniter and more

Read Latest Php CodeIgniter interview questions from below

Download CodeIgniter Interview Questions PDF

CodeIgniter Interview Questions

As the name suggests, helpers help you with tasks.Each helper file is simply a collection of functions in a particular category.They are simple, procedural functions.Each helper function performs one specific task, with no dependence on other functions.

CodeIgniter does not load Helper Files by default, so the first step in using a Helper is to load it. Once loaded, it becomes globally available in your controller and views.

Helpers are typically stored in your system/helpers, or application/helpers directory

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


Where name is the file name of the helper, without the .php file extension or the “helper” part.
Read More

In Codeigniter, delete function is used to delete the one or more row data from a table.
//DELETE FROM table WHERE id = $id
$conditions =['id' => $id]
$this->db->delete('table_name', $conditions); 

// Deleting records from more than one tables in one go
$tables = array('table1', 'table2', 'table3');
$this->db->where('id', $id);

There are three message types in Codeigniter. They are :

  • Error Messages. These are actual errors, such as PHP errors or user errors.
  • Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.
  • Informational Messages. These are the lowest priority messages, simply giving information regarding some process.

By default, all logs in Codeigniter are stored in logs/ directory. To enable error logging you must set the “threshold” for logging in application/config/config.php. Also, your logs/ must be writable.

$config['log_threshold'] = 1;

$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')


Csrf is used to set the protection in CodeIgniter. To set csrf, you have to put the corresponding config value True.

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

All Routing rules in Codeigniter are defined in your application/config/routes.php file.

order_by function is used to order the records from a table in CodeIgniter.
// Getting random rows from database in CodeIgniter
$this->db->order_by("column_name", "random");
$result = $this->db->get()->result(); 

In Codeigniter, models will typically be loaded and called from within your controller methods. To load a model you will use the following method:


If your model is located in a sub-directory, include the relative path from your model’s directory. For example, if you have a model located at application/models/blog/Posts.php you’ll load it using:


Once your Model loaded, you will access its methods using an object with the same name as your controller:


class Blog_controller extends CI_Controller {
        public function blog()

                $data['query'] = $this->blog->get_last_ten_entries();

                $this->load->view('blog', $data);

In system/core/CodeIgniter.php, check CI_VERSION constant value define(‘CI_VERSION’, ‘3.0.6’);

An inhibitor is an error handling class in Codeigniter. It uses PHP ‘s native functions like register_shutdown_function , set_exception_handler, set_error_handler to handle parse errorsexceptions, and fatal errors.

In Codeigniter, you can link images/CSS/JavaScript by using the absolute path to your resources.

Something like below

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

CodeIgniter DB Class insert_id() method is used to get last insert id.


function add_post($post_data){
   $this->db->insert('posts', $post_data);
   $insert_id = $this->db->insert_id();
   return  $insert_id;
Object-relational mapping (ORM) is programming technique for converting data between incompatible type systems using object-oriented programming languages. Below is the list of ORM’s supported by CodeIgniter Framework
  • DataMapper
  • Doctrine
  • Gas ORM