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

#1 How to get random records in MySQL using CodeIgniter?

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

#2 What is inhibitor are Codeigniter?

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.

#3 How to check a field or column exists in a table or not in Codeigniter?

Code for Checking a field or column exists or not in a Codeigniter table.

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

#4 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.
abc.com/user/edit/ramesh

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

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

Prepare 10  Essential Magento Interview Questions

#5 How many types of messages can you log in Codeigniter?

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.

#6 What is_cli() method does in Codeigniter?

In Codeigniter is_cli() method is used to check request is from the command line or not.
Returns TRUE if the application is run through the command line and FALSE if not.

#7 How to set or get config variables in Codeigniter?

In Codeigniter by default all config variables are located at “application/config/config.php” file.
Below is the way to set or get a config variable in Codeigniter
// Setting a config variable dynamically
$this->config->set_item('variable_name', value);
// Getting value of config variable in Codeigniter.
$this->config->item('variable_name');

#8 How you will use or load CodeIgniter libraries

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

Usage:
//Loading Cart library

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

Using Cart library methods

$data = array(
        'id'      => 'sku_9788C',
        'qty'     => 1,
        'price'   => 35.95,
        'name'    => 'T-Shirt',
        'options' => array('Size' => 'L', 'Color' => 'Red')
);

$this->cart->insert($data);

#9 How to get last inserted id in CodeIgniter?

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

Usage:

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

#10 How to check the version of CodeIgniter framework?

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

#11 List the resources that can be autoloaded in Codeigniter?

The following items can be loaded automatically:
  • Classes found in the libraries/ directory
  • Helper files found in the helpers/ directory
  • Custom config files found in the config/ directory
  • Language files found in the system/language/ directory
  • Models found in the models/ folder

To autoload resources, open the application/config/autoload.php file and add the item you want loading to the autoload array. You’ll find instructions in that file corresponding to each type of item.

#12 Explain what is Codeigniter?

CodeIgniter is a powerful MVC based PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

Also Prepare: Frequently Asked Kohana Framework interview questions

#13 How to implement validations in Codeigniter?

#14 List some features provided by CodeIgniter?

  • Framework with a small footprint
  • Simple solutions over complexity
  • Clear documentation
  • Exceptional performance
  • Strong Security
  • Nearly zero configuration

#15 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

Ask a Question