CodeIgniter Interview Questions and Answers
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
It is called as loosely based mvc framework because in codeigniter controller is the necessary but model and view are optional. It means we can build a website without model.
CodeIgniter can be installed with four steps that are given below:
- Download it from its download page & then unzip the package.
- Upload its files and folders on your server or localhost.
- Open
application/config/config.php
file and set base URL. - If you want to use database then open
application/config/database.php
file and set your database credientails. - Now it's installed
If you want to configure additional setting then you can click here
We need only PHP version 5.6 or greater than 5.6. because of potential security and performance issues.
You have to pass your helpers in array form. Here helper_1, helper_2, helper_3, helper_4 are different helpers that we want to load.
$this->load->helper(
array('helper_1', 'helper_2', 'helper_3', 'helper_4')
);
If you want to enable hooks then you have to enabled/disabled by setting in the application/config/config.php
file.
If you want to enable hooks then use this $config['enable_hooks'] = TRUE;
In CodeIgniter drivers are a very special type of Library that has a parent class and its child classes. Child classes have the access to its parent class but not their siblings. It provides an elegant syntax in your controllers file for libraries.
It can found in the system/libraries/ directory.
If we want to use a driver we have to initialize it within a controller with this given method.
$this->load->driver('class_name');
Here class_name is the name of the driver class which we want to invoke.
How we can create our own drivers in CodeIgniter.
- You can create your own driver folder in
/application/libraries/
- Create your_Your_Driver_name.php file in
/application/libraries/Your_Driver
- In
/application/libraries/Your_Driver/drivers
- Your_Driver_name_subclass_1.php
- Your_Driver_name_subclass_2.php
You can use $this->db->last_query();
to display the query string.
You can use print_r($query);
to display the query result.
You can create your custom 404 page with these steps. Please follow these steps one by one.
- You have to update your own created controller's class with
$route['404_override'] = 'Controller_Class_Name';
. You have to update this in yourapplication/config/routes.php
- Please create your new controller "
Controller_Class_Name
" file in your controllers directoryapplication/controllers/
. - Please put this code in your Controller_Class_Name.php
class Controller_Class_Name extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->output->set_status_header('404');
$this->load->view('error_page_404');
}
} - Now create your "error_page_404" view file.
You can use $this->db->insert();
to insert data in your database in Codeigniter.
If you want to insert this in your "Admin Table".
$dataArray = array(
'name'=>'bestinterviewquestion.com',
'phone'=>'9971083635',
'email'=>'[email protected]'
);
$this->db->insert('Admin',$dataArray);
// Here "Admin" is My TableName
You can use $lastInsertID = $this->db->insert_id();
after insert query.
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