Home >>Interview Questions >CodeIgniter Interview Questions

CodeIgniter Interview Questions

General CodeIgniter Interview Questions

1-What is Codeigniter ?

Codeigniter based on the MVC pattern is an open sourced framework which develops websites for PHP.  

2-What are Hooks in Codeigniter ?

Hooks are a feature in codeigniter which help the user to change the inner working without having to change the core files. They are represented by application/config/hooks.php.file. Hooks are more often to be used in executing a script with a particular path within codeigniter.  

3-What are Helpers in Codeigniter ?

Helpers is the feature in codeigniter where it assists the user in performing specific function. The helper will vary according to the function it’d be assisting such as url helpers will assist in creating links whereas text helpers assist in performing text formatting routines.  

4-How Do You Load a Model in Codeigniter ?

To load a file in codeigniter you use

  • $this->load->model (‘Model_Name’);

 

5- What is Routing in Codeigniter ?

Routing is defined as serving PHP files in an alternative way rather than accessing it from the browser. This allows the user to gain unlimited freedom in customizing the default URL pattern to fit his own requirement.  

6- What are the Security Parameters in Codeigniter ?

To prevent hacking and other malicious activities codigniter applies a cross site scripting hack filter which will automatically start to filter all post and cookie data while comparing it to existing methods that are used to trigger javascript and once an anomaly is detected it is automatically converted into character entries.  

7-How to Do You Link Images From a View in Codeigniter?

To link images from a view in a codeigniter first use an absolute path to the resources required and link the image from a view in codeigniter /css/styles.css /js/query.php /img/news/566.gpg  

8-What is an Inhibitor in Codeigniter ?

Inhibitor is a specialist class in codeigniter which primarily functions as a means to combat or handle errors and is primarily comprised of functions such as set_exception_handler set_error_handler register_shutdown_function which are useful in handling parse errors exceptions and fatal errors.  

9-What is the Default URL Pattern in Codeigniter ?

The default URL patter in codeigniter is split up into four functions which start with the server name,controller class controller name and finally function parameters To accesses the URL pattern in codeigniter you have to use a URL helper.  

10-How Can You Extend the Class in Codeigniter ?

To extend a native input class the user must first build a file which is to be named application/core/MY_Input.php And then proceed to declare the class with Class MY_Input extends CI_Input { }  

11-How Do You Prevent Codeigniter From CRSF ?

The most common way to protect codeigniter form CRSF is to use a hidden field in every form of the website. This hidden field will be used as a CRSF token which in a random value which changes each and every HTTP request sent. When inserted into a website form it is saved in the user session if the request is the same it becomes legit.  

12- How Do You Enable CRSF in Codeigniter ?

To enable CRSF the user must follow these steps application/config/config.php file and setting it to $config [ ‘csrf_protection’] = TRUE;

13. What are the most prominent features of CodeIgniter?

There are many features that are prominent and are availed to us by the Codeigniter.
Here is a list of the most important features of the Codeigniter depicted below:

  • CodeIgniter is basically an open source framework that is generally free to use.
  • Codeigniter is known for being the most light-weighted framework.
  • Model View Controller (MVC) pattern is the pattern on which the codeigniter is based.
  • It generally possesses the full featured database classes and is known to support for several platforms.
  • Codeigniter is extensible that simply means that the programmers can extend the system very easily just by the use of their libraries, helpers.
  • It is mostly known for its excellent documentation.

14. Elaborate MVC in CodeIgniter.

MVC is the pattern on which the whole of codeIgniter framework is based. Now let’s get to know the MVC, it is basically a software that delivers the users a separate logical view from the presentation view.

This results in a web page that contains the minimal scripting.

  • Model - The models are basically managed by the controller. The data structure of the programmer is generally represented by the model. Model classes consist of the functions by the help of which programmers can insert, retrieve or update information in their database.
  • View - The information that is generally displayed in front of the users is known as the view. A view can be either a web page or parts of the page such as header and footer.
  • Controllers - The intermediary that is present between the models and the view that is used to process HTTP request and in generating a web page is known as the controller. Models and view are the one that process the information of the requests that are received by the controller and passed on to them.

15. What do you mean by the model in CodeIgniter.

Model in the CodeIgniter is generally responsible to handle all the data logic and the representation and loading of the data that are present in the views. The model in the CodeIgniter is generally stored in the application/models folder.

Here is the basic structure of a model file is depicted below for you to understand:

class ModelName extends CI_Model
{
	public function MethodName()
	{
	
	}
}

In the above mentioned structure, the ‘ModelName’ is representing the name of the programmer’s model file. Please note that the class first letter should be in an uppercase letter that should be followed by the various other lowercase letters, and it should be generally the same as the name of the file of the programmer. All the built-in methods of parent Model file basically gets inherited to the newly created file as the base CodeIgniter Model is extended by the model name.

16. How can the user can connect models to a database manually?

In order to connect the models to a database manually the following depicted syntax is used:

$this->load->database();

17.Elaborate the views in the CodeIgniter.

All the markup files like header, footer, sidebar, etc are present in the view folder. In order to reuse them the programmer has to embed them in the controller file anywhere. This is to be done as they can't be called directly hence, they have to be loaded in the controller's file.

Syntax of the view:

In order to view the syntax the programmers have to create a file and have to save that in the application/views folder. For a better understanding please review the following example:

<!DOCTYPE html>
<html>
<head>
	<title>Codeigniter View</title>
</head>
<body>
	<h1>Codeigntier View</h1>
</body>
</html>

18. How can you load a view in CodeIgniter?

In the Codeigniter, the View can't be accessed directly as of the fact that it is loaded in the controller file for always. Here is the function that is depicted below is used to load a view page:

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

19. What do you mean by the controller in CodeIgniter.

The intermediary present between the models and the views to process the HTTP request and is used to generate a web page is known as a controller. It is basically known as the center of each request that exists on the web application of the user.

Please consider the following URL in this reference,

projectName/index.php/welcome/

In this URL the CodeIgniteris basically trying to find the welcome.php file and the Welcome class.

Controller Syntax
class ControllerName extends CI_Controller
{
	public function __construct()
	{
	parent::__construct();
	}
	public function MethodName()
	{
	
	}
}

20. What is the default controller in CodeIgniter?

Whenever there is no file name is mentioned in the URL then the file will be specified in the default controller loaded by default. By default, the file name is welcome.php that is known as the first page that is to be seen after installing CodeIgniter.

localhost/codeigniter/  

In this case the Welcome.php will generally be loaded as if there is no file name mentioned in the URL provided.

The programmer can generally change the default controller that is present in the file application/config/routes.php as per his/her need.

$route['default_controller'] = ' '; 

In the above syntax the programmer has to specify the file name that he/she basically wants to get loaded as the default.

21. How can a constructor be called in CodeIgniter?

In order to use a constructor, the programmer has the need to mention the below depicted line of code,

parent::__construct()

22. What is the basic CodeIgniter URL structure?

The basic CodeIgniter URL structure generally uses a segment based approach instead of using the 'query-string' approach.

The basic CodeIgniter URL structure is as depicted below:

projectName/index.php/class/method/ID

A controller class that generally needs to be invoked is represented by the Class.

ID is basically an additional segment that is passed to the controllers.

23. What do you mean by an inhibitor of CodeIgniter ?

Inhibitor is generally known to be an error handler class in the CodeIgniter that basically uses the native PHP functions such as set_error_handler, set_exception_handler, register_shutdown_function in order to handle the parse errors, exceptions, and the fatal errors.

24. How can the programmer load multiple helper files?

In order to load the multiple helper files the programmer generally have to specify them in an array just like depicted below:

$this->load->helper(array('helper1', 'helper2', 'helper3'));  

25. Elaborate the CodeIgniter library. How will you load it?

A rich set of libraries is generally availed by the CodeIgniter. As it generally enhances the developing speed of an application hence, it is known as the essential part of the CodeIgniter. The normal location of this in the CodeIgniter is the system/library.
Here is how a programmer can load it, just by following the code depicted below:

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

26. How can the programmer create a library in CodeIgniter?

There are generally three methods that can be used to create a library that are depicted below:

  • By creating an entire new library
  • By extending native libraries
  • By replacing native libraries

27. Where is a library that is newly created stored in CodeIgniter structure?

A library that is newly created in CodeIgniter structure should generally be placed in application/libraries folder.

28. Can a programmer extend the native libraries in CodeIgniter?

The answer is indeed, a programmer can add some of the extended functionality to a native library just by adding one or two methods in it. These methods will replace the entire library with the programmer’s version. Hence, it is always better to extend the class. Please note that the extending and replacing in codeIgniter is almost known to be identical with only exceptions that are depicted below:

  • This exception includes that the class declaration must enlarge the parent class.
  • Every new class name and the filename must be prefixed with MY_ in this exception.