Sharing Latest 30+ 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

List some features provided by CodeIgniter?

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:

$this->load->helper('name');

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

Explain routing in CodeIgniter?

In Software engineering routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request.In Codeigniter typically there is a one-to-one relationship between a URL string and its corresponding controller class/method.The segments in a URI normally follow this pattern:example.com/class/function/id/.In CodeIgniter, all routing rules are defined in your application/config/routes.php file.

What are Sessions In CodeIgniter? How to read, write or remove session in CodeIgniter?

Sessions in CodeIgniter

In CodeIgniter Session class allows you maintain a user’s “state” and track their activity while they are browsing your website. In order to use session, you need to load Session class in your controller.

$this->load->library(‘session’); method is used to sessions in CodeIgniter

$this->load->library('session');

Once loaded, the Sessions library object will be available using:

$this->session

Reading session data in CodeIgniter

Use $this->session->userdata(); method of session class to read session data in CodeIgniter.

Usage

$this->session->userdata('your_key');

You can also read a session data by using the magic getter of CodeIgniter Session Class

Usage

$this->session->item

Where an item is the name of the key you want to retrieve.

Creating a session in CodeIgniter

Session’s Class set_userdata() method is used to create a session in CodeIgniter. This method takes an associative array containing your data that you want to add in session.