CodeIgniter Interview Questions

A list of frequently asked CodeIgniter interview questions and their answers are given below.

1) What is CodeIgniter?
CodeIgniter is an open source framework used for developing web applications on PHP. It is based on MVC pattern which resembles to Cake PHP. CodeIgniter contains it's own framework libraries with simple interface and logical structure to access these library functions, plug-ins, helpers and other framework resources which solve the PHP development needs more easily maintaining high performance. It simplifies the PHP code and provides a fully interactive, dynamic website in a much shorter time.

2) What are the special features of CodeIgniter?
Following are the list of special features of CodeIgniter:

It is an open source framework and free to use.
It is an extremely light weighted framework.
It is based on the Model View Controller (MVC) pattern.
It has built in database classes and support for several platforms.
It is extensible and you can easily reuse the framework to create your own libraries and helpers.

3) What is the current version of CodeIgniter?
CodeIgniter 3.1.9 is the latest version of the framework. You can download it from here

4) Explain the folder structure of CodeIgniter.
If you download and unzip CodeIgniter, you will get the following file structure/folder structure:

Application (It is a main application folder where we can put our customized code within)

cache
Config
Controllers
core
errors
helpers
hooks
language
libraries
logs
models
third-party
views 

system (It contains all CodeIgniter framework defined reusable core code) 

core
database
fonts
helpers
language
libraries

5) Explain architecture of CodeIgniter. 
CodeIgniter is designed to deliver maximum and optimized performance in a less time. Technically, CodeIgniter is loosely coupled MVC pattern framework where components rely very less on each other. CodeIgniter provides dynamically instantiation with light-weighted MVC feature. 

6) Explain MVC in CodeIgniter. 
CodeIgniter framework is based on MVC pattern. MVC is a software pattern that provides you a separate layering between logical view and the presentation view which gives a web page with necessary and minimum content. Model - Model represents the business logic processing unit. The model is managed by controller. Model classes contain functions where you can perform CRUD operation which means create, read, update and delete the information in your database. View - View is the information dispalyed in front of users (UI). It can be a complete web page or a part of the page like header, content, left column, right column and footer. Controllers - Controller is the connection bridge between model and view to process HTTP request and generate a web page. All the requests received by the controller are passed on to models and view to process the information. 

7) Enlist all the databases supported By CodeIgniter Framework? 
Following Databases supported are supported by Codeigniter Frameworks: MySQL (5.1+) MS SQL Oracle SQLite Interbase/Firebird ODBC CUBRID PostgreSQL 

8) Explain Model ?
In CodeIgniter, model is used to handle all data logic and representation and load data in the views. It is stored in application/models folder. You can declare the basic structure of a model file shown below: 
class Modelname extends CI_Model {
    function __construct(){
        parent::__construct();
    }
}
In the above Model class, Modelname is the name of your model file and thing to remember is first letter of class name must be in an uppercase letter followed by other lowercase letters, and it should be the same as your file name in models folder. It extends the base CodeIgniter Model so that it can use all the built-in methods of parent Model file which gets inherited to the newly created file. 

9) How can you add or load a model in CodeIgniter? 
To load existing created models in controller functions, use the following syntax of model function: 
$this->load->model('Modelname');

If your model file is located in sub-directory of the model folder, then you have to mention the full path. For example, if your file location is application/controller/models/example/Modelname, you can use following syntax to load your file: 
$this->load->model('example/Modelname'); 


10) Explain views in CodeIgniter.
View folder contains all the important common page files like header, footer, sidebar, etc. They can be reused anywhere in controller file. Views need to be loaded in the controller's file. Syntax to load a view: Create a file and save it in application/views folder. For example, we have created a file Myview.php, 
View Page

11) How can you load a view in CodeIgniter?
The view files are always loaded in the controller file and can't be accessed directly. Following function is used to load a view page: 
$this->load->view('view_name');  

Now, go to your controller file (Test.php) and write this code as shown below.

class Test extends CI_Controller {
    public function index()
    {
        $this->load->view('myview'); // This is your view file name without .php extension
    }
}


12) Explain controller in CodeIgniter.
A controller is the bridge between models and views to process the HTTP request and generate a web page. It is the center of every request on your web application. Consider following URL, 
www.mysite.com/index.php/test/  

In this URL, CodeIgniter try to find Test.php file and Test class. 

class Test extends CI_Controller {
    public function index()
    {}
}
In above code snippet, controller's file name is Test.php (the first letter must be an uppercase), and the class name is Test (the first letter must be in uppercase). 

13) How to connect models to database? 
You can use the following syntax to connect database: 
$this->load->database();  
 

14) What is inhibitor of CodeIgniter? 
In CodeIgniter framework, Inhibitor is an error handler class that uses native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.

15) What is the default method name in CodeIgniter? 
In CodeIgniter framework, controller always calls index method by default. If you want to call a different method, then write it in the controller's file and specify it's name while calling the function. 
www.mysite.com/index.php/test/  
 

16) What is a helper function in CodeIgniter? 
How to load a helper file? Helpers are the reusable library functions that are used to perform specific tasks. URL Helpers: used to create the links. Text Helpers: used for text formatting. Cookies Helpers: used for reading and setting cookies. 

17) How to load multiple helper files? 
To load multiple helper files, specify them in an array: 
$this->load->helper(  
array('helper1', 'helper2', 'helper3')  
); 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s