CODEIGNITER Interview Questions and Answers

CodeIgniter is a free, light weight,fast and Application Development Framework for building web sites using PHP. It is based on MVC i.e. Model-View-Controller design pattern.It helps us to focus on project by minimizing the amount of code needed for given task..

1) What is the current version of Codeigniter and how to check the version of CodeIgniter framework?

The current version of the CodeIgniter framework is 3.1.10. We can check the version of codeigniter framework in system/core/CodeIgniter.php file, where you can check CI_VERSION constant value as define(‘CI_VERSION’, ‘3.1.10’);

2) What is the default URL pattern used in Codeigniter framework?

In CodeIgniter, URLs are designed to be search-engine and human-friendly.CodeIgniter uses a segment-based approach rather than using “query string” based approach.

The default URL pattern in CodeIgniter consists of 4 main components. They are :

  1. A server name (
  2. A Controller (user)
  3. An Action or method (edit)
  4. An optional action parameter (id)

3) Explain helpers in CodeIgniter and how to load helper file?

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.

Loading Multiple Helpers:



4) What are the hooks in codeigniter?

CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files.How ever you like to cause some action to take place at a particular stage in the execution process.

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:

  1.  $hook['pre_controller'] = array(
  2. 'class' => 'MyClass',
  3. 'function' => 'Myfunction',
  4. 'filename' => 'Myclass.php',
  5. 'filepath' => 'hooks',
  6. 'params' => array('param1', 'param2', 'param3')
  7. ); 

5) How you will add or load an model in codeigniter?

Models will typically be loaded and called from within your controller functions. To load a model you will use the following function:


6) How do you get last inserted ID in Codeigniter?

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

Syntax: $this->db->insert_id();

Usage : 

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

7) How to print SQL statement in codeigniter model?

In codeigniter, to print query in model we use : 


8) What are the different types of hook are there in Codeigniter?

The following is a list of available hook points:

  • pre_system Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.
  • pre_controller Called immediately prior to any of your controllers being called. All base classes, routing, and security checks have been done.
  • post_controller_constructor Called immediately after your controller is instantiated, but prior to any method calls happening.
  • post_controller Called immediately after your controller is fully executed.
  • display_override Overrides the _display() method, used to send the finalized page to the web browser at the end of system execution. This permits you to use your own display methodology. Note that you will need to reference the CI superobject with $this->CI =& get_instance() and then the finalized data will be available by calling $this->CI->output->get_output().
  • cache_override Enables you to call your own method instead of the _display_cache() method in the Output Library. This permits you to use your own cache display mechanism.
  • post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.

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


10) Explain MVC in Codeigniter?




