1 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.
CodeIgniter is another open source PHP framework which is specifically employed for the development of dynamic websites. With the help of CodeIgniter, one can build simple yet elegant tools which could further be utilized to design web programs and applications with full dynamic features.
What is CodeIgniter? CodeIgniter is easy to use an open-source MVC based framework for PHP. It is a loosely coupled framework that is used for the rapid development of websites and mobile APIs. Here you can read about CodeIgniter helpers, sessions, hooks, Routing, Constants ORM supported by Codeigniter and more.
| CodeIgniter is written In | PHP Programming Language |
| CodeIgniter is a | Open Source Loosely Coupled MVC Framework |
| CodeIgniter is developed By | BCIT Recreation Services |
| CodeIgniter is based on | MVC architectural pattern |
| CodeIgniter Dependencies | Php 5.6+,MYSQL 5.1+,PDO Driver |
| CodeIgniter Licence | MIT License |
| CodeIgniter Features | Lightweight, Pagination, Localization, FTP class, Data Encryption, Session Management, etc. |
As a CodeIgniter developer, some of the key responsibilities you may be expected to have include:
In CodeIgniter Interview Questions interviews, it's important to clearly explain key concepts and demonstrate your coding skills in real-time. Practice articulating your thought process while solving problems, as interviewers value both your technical ability and how you approach challenges.
Our team has carefully curated a comprehensive collection of the top CodeIgniter Interview Questions to help you confidently prepare, impress your interviewers, and land your dream job.
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.
As of Sept 19, 2019, CodeIgniter 3.1.11 is the latest version of the framework. You can download it from here
In system/core/CodeIgniter.php, check CI_VERSION constant value define(‘CI_VERSION’, ‘3.0.6’);
Following Databases supported are supported by Codeigniter Frameworks
There are some popular Codeigniter features in below:
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
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.
CodeIgniter’s Hooks feature provides a way to modify the inner workings or functionality of the framework without hacking the core files.
The following is a list of available hook points.
CodeIgniter uses a few functions for its operation that are globally defined and are available to you at any point. These do not require loading any libraries or helpers.
Read Best 80+AngularJS Interview Questions
To set the default timezone in Codeigniter open application/config.php file and add below code in it.
date_default_timezone_set('your timezone');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'); ?>" />
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 errors, exceptions, and fatal errors.
Follow below steps to index.php from URL in Codeigniter
$config['index_page'] = "index.php" to $config['index_page'] = "" and $config['uri_protocol'] ="AUTO" to $config['uri_protocol'] = "REQUEST_URI"
RewriteEngine on RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
In Codeigniter, models will typically be loaded and called from within your controller methods. To load a model you will use the following method:
$this->load->model('model_name');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:
$this->load->model('blog/Posts');Once your Model loaded, you will access its methods using an object with the same name as your controller:
Example
class Blog_controller extends CI_Controller {
public function blog()
{
$this->load->model('blog');
$data['query'] = $this->blog->get_last_ten_entries();
$this->load->view('blog', $data);
}
}
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
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.
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.
Example
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe@some-site.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
If you want to add userdata one value at a time, set_userdata() also supports this syntax:
$this->session->set_userdata('some_name', 'some_value');Session’s Class unset_userdata() method is used to remove a session data in CodeIgniter. Below are example usages of same.
Unset particular key
$this->session->unset_userdata('some_key');Unset an array of item keys
$array_items = array('username', 'email');
$this->session->unset_userdata($array_items);
Read More https://www.codeigniter.com/userguide3/libraries/sessions.html
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;
}
$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);
CLI is a text-based command-line interface for interacting with computers via a set of commands.
In Codeigniter, we can use CLI for
We can use redirect helper to do 301 redirects in Codeigniter.
Syntax :
redirect($uri = '', $method = 'auto', $code = NULL)
Parameter:
$uri (string) – URI string
$method (string) – Redirect method (‘auto’, ‘location’ or ‘refresh’)
$code (string) – HTTP Response code (usually 302 or 303)
Return type: void
Sample Usage:-
redirect('/posts/13', 'New location', 301);
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...
}
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.
Below images give you an understanding of how data flows throughout the system in Codeigniter.

Source: https://www.codeigniter.com/user_guide/overview/appflow.html
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');
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
$id=1;
$tables = array('table1', 'table2', 'table3');
$this->db->where('id', $id);
$this->db->delete($tables);
You can implement form validations in Codeigniter using a form_validation library. Below is simple server-side validation in Codeigniter.
In your Controller
$this->load->helper(array('form'));
/* Load form validation library */
$this->load->library('form_validation');
/* Set validation rule for name field in the form */
$this->form_validation->set_rules('firstname', 'FirstName', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('myform');
}
else {
$this->load->view('formsuccess');
}
In your View
<?php echo validation_errors(); ?>
abc.com/user/edit/ramesh
The default URL pattern in CodeIgniter consists of 4 main components. They are :
Prepare 10 Essential Magento Interview Questions
// 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();
Codeigniter Is Called a loosely based MVC framework, this is because unlike others the controllers’ classes such as models and views are not mandatory in CodeIgniter. Moreover, one can modify CodeIgniter to utilize HMVC as well.
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.
All Routing rules in Codeigniter are defined in your application/config/routes.php file.
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;
There are three message types in Codeigniter. They are :
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;
PHP Frameworks
Laravel is a free, open-source PHP web framework w ...
PHP Frameworks
Cake PHP is open-source software that has gained h ...
PHP Frameworks
Phalcon is a high-performance, full-stack PHP fram ...
PHP Frameworks
FuelPHP is an open-source web application framewor ...
PHP Frameworks
...
PHP Frameworks
...
PHP Frameworks
...
PHP Frameworks
Yii is an open-source PHP framework which aids rap ...
PHP Frameworks
...
PHP Frameworks
...
PHP Frameworks
Zend is an object-oriented open-source PHP framewo ...
PHP Frameworks
Symfony was sponsored by an open-source SensioLabs ...
PHP Frameworks
...
PHP Frameworks
...
PHP Frameworks
...
PHP Frameworks
...
Practice with our interactive coding challenges and MCQ tests to boost your confidence and land your dream JavaScript developer job.