Top 30 Codeigniter Interview Questions You Must Prepare 27.Jul.2024

Q1. What Is The Default Method Name In Codeigniter?

By default controller always calls index method. If you want to call a different method, then write it in the controller?s file and specify its name while calling the function.

Q2. What Are The Security Parameter For Xss In Codeigniter?

Codeigniter has got a cross-site scripting hack prevention filter. This filter either runs automatically or you can run it as per item basis, to filter all POST and COOKIE data that come across. The XSS filter will target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it detects any suspicious thing or anything disallowed is encountered, it will convert the data to character entities.

Q3. What Is Stable Version Of Codeigniter?

Version: 3.0.5,
Date January 13, 2016

Q4. Why Codeigniter Is Called As Loosely Based Mvc Framework?

Reason behind this is we does not need to follow strict mvc pattern while creating application.We can also able to build with model only view and controllers are enough to built a application.

Q5. Can You Extend Native Libraries In Codeigniter?

Yes, we can add some extended functionality to a native library by adding one or two methods.

Q6. Explain Application Flow Chart In Codeigniter?

The following graphic illustrates how data flows throughout the system:

CodeIgniter application flow:

  1. The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
  2. The Router examines the HTTP request to determine what should be done with it.
  3. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
  4. Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
  5. The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.
  6. The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.

Q7. Explain Mvc In Codeigniter?

CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.

The View is the information that is being presented to a user.

A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of “page”.

The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.

Q8. Who Developed Codeigniter?

Codeigniter was developed by ellislab Inc.

Q9. Explain Codeigniter Architecture?

From technical point of view, CodeIgniter is dynamically instantiation (light-weighted), loosely coupled (components rely very less on each other) and has component singularity (each class and functions are narrowly focused towards their purpose).

Q10. What Are The Most Prominent Features Of Codeigniter?

A list of most prominent features of CodeIgniter:

  • It is an open source framework and free to use.
  • It is extremely light weighted.
  • It is based on Model View Controller (MVC) pattern.
  • It has full featured database classes and support for several platforms.
  • It is extensible. You can easily extend system by using your own libraries, helpers etc.
  • Excellent documentation.

Q11. What Is Helper In Codeigniter? How Can You Load A Helper File?

Helpers are the group of functions in a particular category that assist you to perform specific functions.

In CodeIgniter, there are many helpers like:

URL Helpers: helping in creating links.

Text Helpers: perform various text formatting routines.

Cookies Helpers: set and read cookies.

To load helper file, use the following command:

$this->load->model('ModelName');  

Q12. Explain Codeigniter File Structure?

following are the folder structure :-

application:

  • cache
  • Config
  • Controllers
  • core
  • errors
  • helpers
  • hooks
  • language
  • libraries
  • logs
  • models
  • thirdparty
  • views

system:

  • core
  • database
  • fonts
  • helpers
  • language
  • libraries

Q13. In Which Language Codeigniter Is Written?

PHP

Q14. Explain Remapping Method Calls In Codeigniter?

Second segment of URI determines which method is being called. If you want to override it, you can use _remap() method. The _remap method always get called even if URI is different. It overrides the URI

Q15. What Is Codeigniter?

Codeigniter is an open source framework for web application on PHP. It is loosely based on MVC pattern and it is similar to CakePHP.

Q16. How Can You Connect Models To A Database Manually?

To connect database manually use following syntax,

$this->load->database(); 

Q17. Explain Views In Codeigniter?

View folder contains all the markup files like header, footer, sidebar, etc. They can be reused by embedding them anywhere in controller file. They can't called directly, they have to be loaded in the controller's file.

Q18. How Can You Load A View In Codeigniter?

View can't be accessed directly. It is always loaded in the controller file.

Following function is used to load a view page:

$this->load->view('page_name');  

Q19. Explain Controller In Codeigniter?

A controller is the intermediary between models and views to process HTTP request and generates a web page. It is the center of every request on your web application.

Q20. Explain Codeigniter Library. How Will You Load It?

CodeIgniter provides a rich set of libraries. It is an essential part of CodeIgniter as it increases the developing speed of an application. It is located in the system/library.

It can be loaded as follows,

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

Q21. How Can You Create A Library In Codeigniter?

There are three methods to create a library:

  • Creating an entire new library
  • Extending native libraries
  • Replacing native libraries

Q22. What Is Basic Codeigniter Url Structure?

Instead of using 'query-string' approach, it uses a segment based approach.

Its structure is as follows,

abc.com/class/function/ID  

class represents controller class that needs to be invoked.

function is the method that is called.

ID is any additional segment that is passed to controllers.

Q23. What Are The Features Of Codeigniter? Open Source Framework?

  1. Light Weight
  2. CodeIgniter is Extensible
  3. Full Featured database classes

Q24. How Can You Add Or Load A Model In Codeigniter?

To load models in controller functions, use the following function:

$this->load->model('ModelName');  

Q25. How You Will Work With Error Handling In Codeigniter?

CodeIgniter lets you build error reporting into your applications using the functions described below. In addition, it has an error logging class that permits error and debugging messages to be saved as text files.

show_error(‘message’ [, int $statuscode= 500 ] )

This function will display the error message supplied to it using template application/errors/errorgeneral.php.

show_404(‘page’ [, ‘logerror’])

This function will display the 404 error message supplied to it using template application/errors/error404.php.

log_message(‘level’, ‘message’)

This function lets you write messages to your log files. You must supply one of three “levels” in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the second parameter.

Q26. How Do You Use Aliases With Autoloading Models In Codeigniter?

We can auto load model like this:

$autoload[‘model’] = array(array(‘usersmodel’, ‘users’), array(‘newsmodel’, ‘news’), ‘categorymodel’);

Q27. How To Access Config Variable In Codeigniter?

$this->config->item(‘variable name’);

Q28. How Can You Extend Class In Codeigniter?

You have to build a file name application/core/MY_Input.php and declare your class with Class MY_Input extends CI_Input {}to extend the native input class in CodeIgniter.

Q29. How To Get Random Records In Mysql Using Codeigniter?

We can use this:

$this->db->order_by(‘id’,’RANDOM’);

Q30. How To Unset Session In Codeigniter?

$this->session->unsetuserdata(‘somename’);;