CodeIgniter Interview Questions and Answers

Last updated on Mar 24, 2024
  • Share
CodeIgniter Interview Questions

CodeIgniter is a PHP open-source web development framework for building dynamic websites. Based on the MVC development pattern, Codeigniter can be modified to use the HMVC pattern. This pattern allows developers to maintain controller, view, and models in a sub-directory format. This framework is known for its higher speed as compared to other PHP frameworks. If you are looking for Codeigniter interview questions, we can help you!

A Quick Overview of CodeIgniter
What is Codeigniter? It is a PHP open-source web development framework for building dynamic websites. Based on the MVC development pattern, Codeigniter can be modified to use the HMVC pattern.
Latest Version 4.0, released on September 3, 2019
Stable Version 3.1.10, released on January 16, 2019
Created By EllisLab
Written in PHP
License MIT License

Most Frequently Asked CodeIgniter Interview Questions

Here in this article, we will be listing frequently asked CodeIgniter Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q11. What do you mean by Get_instance in CodeIgniter?
Answer

It is a globally available methods or functions that returns the Controller super-object which contains all the currently loaded classes. get_instance() function  returns the Controller class instance.

Q12. What do you mean by routing in Codeigniter?
Answer

It is the process of taking a URI endpoint and decomposing it into parameters to determine module controller and action of that controller should receive the request.

 

CodeIgniter has a userfriendly URI routing rule so that we can re-route URL easily . There is a one-to-one relationship between a URL string and its corresponding controller class and its methods.

 

Routing is a technique through which we can converts SEO friendly URLs into a server code format that easily understandable.

 

We can manage these from routes.php file at the located in application/config.

Q13. List some different hook point in Codeigniter?
Answer

Codeigniter supports various hook points.

  • post_controller_constructor
  • pre_controller
  • post_sytem
  • pre_system
  • cache_override
  • display_override
  • post_controller

If you are scrolling on the web for Codeigniter interview questions for 2 year experience pdf, then this guide will gonna help you.

Q14. How to link images/CSS/JavaScript from a view in codelgniter?
Answer

We can use an absolute path to resources to link images/CSS/JavaScript from a view in CodeIgniter.

For Example :

<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url(); ?>css/responsive.css">
<script type = 'text/javascript' src = "<?php echo base_url(); ?>js/jquery.js"></script>

Q15. What do you mean by inhibitor in CodeIgniter?
Answer

Inhibitor is an error handling class. It is using the native PHP functions like set_error_handler, set_exception_handler, register_shutdown_function to handle all error's like parse errors, exceptions, and fatal errors.

Q16. How to remove index.php from URL in Codeigniter?
Answer

You can follow these given steps to remove index.php from URL in Codeigniter.

  • Please open config.php and change from $config['index_page'] = "index.php" to $config['index_page'] = "";
  • Update also from $config['uri_protocol'] ="AUTO"; to $config['uri_protocol'] = "REQUEST_URI";
  • Put this code in your htaccess file
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Q17. What is CSRF and how you can enable CSRF in CodeIgniter?
Answer

In codeIgniter CSRF token is a random generated value that changes with each HTTP request sent by webform. When the form is submitted by user then website checks this submitted CSRF token equals or not the saved in the session.

We can enable CSRF protection from config.php and update the following values

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name'; //The token name
$config['csrf_cookie_name'] = 'csrf_cookie_name'; //The cookie name
$config['csrf_expire'] = 7200; // It will expire after this given time.

Q18. How to extend the class in Codeigniter?
Answer

You have to build a file with name application/core/Blog.php and declare your class with

Class Blog extends CI_Input {
      // Write your code here
}

Q19. What is Codeigniter Library and how we can load it?
Answer

Codeigniter provides a rich set of libraries, which indirectly increase the speed of developing an application. These Codeigniter system library is located in system/libraries.

In Codeigniter the library can be loaded with $this->load->library('class name');

If we want to load multiple libraries then we can use like $this->load->library(array('comment', 'blog'));

Q20. How to handle sessions in Codeigniter?
Answer
How to add values in session in Codeigniter

$_SESSION['username'] = 'bestinterviewquestion.com' // It can be use in core PHP
$this->session->set_userdata('username', 'bestinterviewquestion.com'); // It can be done in Codeigniter

We can pass array to store values in session in Codeigniter.

$array = array(
    'username' => 'bestinterviewquestion.com',
    'email' => '[email protected]',
    'url' => 'https://www.bestinterviewquestion.com'
);

$this->session->set_userdata($array);

How to remove values in session in Codeigniter

unset($_SESSION['username']); // It can be use in core PHP
$this->session->unset_userdata('username'); // It can be done in Codeigniter

If we want to remove more values from session then we can use like this

$this->session->unset_userdata($array);  // $array is defined above. It is an array with key & values.

How to get data from session in Codeigniter

$this->session->userdata('username'); // Here we will get username, if it is exists in session.

History of Codeigniter

The first version was released in Feb 2006 by EllisLab.

Advantages of Codeigniter

If you are preparing for Codeigniter interview questions, do memorize the powers of CodeIgniter.

  • Easy to learn, handle and customize
  • Flexible and easy to configure
  • Amazing Active Record Implementation
  • Best-in-class documentation
  • Discount, Offers, Coupons and Options and Properties
  • Extensive user base
Reviewed and verified by Umesh Singh
Umesh Singh

My name is Umesh Singh having 11+ experience in Node.JS, React JS, Angular JS, Next JS, PHP, Laravel, WordPress, MySQL, Oracle, JavaScript, HTML and CSS etc. I have worked on around 30+ projects. I lo...