50+ CodeIgniter Interview Questions

50+ CodeIgniter Interview Questions

CodeIgniter Interview Questions

1) What is CodeIgniter? 

CodeIgniter is an open source and ground-breaking system utilized for creating web applications on PHP. It is approximately founded on MVC example and like Cake PHP. CodeIgniter contains libraries, straightforward interface and legitimate structure to get to these libraries, modules, assistants and some different assets which comprehend the intricate elements of PHP all the more effectively keeping up superior. It improves the PHP code and draws out a completely intelligent, unique site at an a lot shorter time.

2) What are the most conspicuous highlights of CodeIgniter? 

A rundown of most noticeable highlights of CodeIgniter:

It is an open source system and allowed to utilize.

It is incredibly light weighted.

It depends on the Model View Controller (MVC) design.

It has full included database classes and backing for a few stages.

It is extensible. You can without much of a stretch broaden the framework by utilizing your libraries, partners.

Phenomenal documentation.

3) Explain the envelope structure of CodeIgniter. 

On the off chance that you download and unfasten CodeIgniter, you get the accompanying record structure/envelope structure:

Application

store

Config

Controllers

center

mistakes

partners

snares

language

libraries

logs

models

outsider

sees

framework

center

database

text styles

partners

language

libraries

4) Explain CodeIgniter engineering. 

From a specialized perspective, CodeIgniter is progressively instantiation (light-weighted), inexactly coupled (segments depend extremely less on one another) and has a part peculiarity (each class and capacities are barely engaged towards their motivation).

Information stream in CodeIgniter

Codelgniter Architecture 1 

5) Explain MVC in CodeIgniter. 

CodeIgniter system depends on MVC design. MVC is a product that gives you a different sensible view from the introduction see. Because of this, a site page contains insignificant scripting.

Demonstrate - The Controller oversees models. It speaks to your information structure. Display classes contain works through which you can embed, recover or update data in your database.

View - View is the data that is exhibited before clients. It very well may be a page or parts the page like header and footer.

Controllers - Controller is the middle person among models and view to process HTTP demand and produces a website page. Every one of the solicitations gotten by the controller are passed on to models and view to process the data.

Demonstrate View-Controller 

6) Explain demonstrate in CodeIgniter. 

Model's duty is to deal with all information rationale and portrayal and burden information in the perspectives. It is put away in application/models envelope.

The fundamental structure of a model document

Codelginator Models 1

Here, ModelName is the name of your model record. Keep in mind, the class first letter must be in a capitalized letter pursued by other lowercase letters, and it ought to be equivalent to your document name. It broadens the base CodeIgniter Model with the goal that all the inherent strategies for parent Model record gets acquired to the recently made document.

7) How would you be able to include or stack a model in CodeIgniter? 

To stack models in controller capacities, utilize the accompanying capacity:

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

On the off chance that in the event that your model record is situated in sub-catalog of the model envelope, at that point you need to make reference to the full way. For instance, if your document area is application/controller/models/venture/ModelName. At that point, your document will be stacked as appeared as follows,

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

8) How would you be able to interface models to a database physically? 

To interface database physically utilize following punctuation,

$this->load->database();

9) Explain sees in CodeIgniter. 

View organizer contains all the markup documents like header, footer, sidebar, and so on. They can be reused by inserting them anyplace in controller record. They can't call straightforwardly, and they must be stacked in the controller's record.

View sentence structure

Make a record and spare it in application/sees envelope. For instance, we have made a record Firstview.php,

Codeignter sees 1 

10) How would you be able to stack a view in CodeIgniter? 

The View can't be gotten to legitimately. It is constantly stacked in the controller record. Following capacity is utilized to stack a view page:

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

Compose your view's page name in the section. You don't have to determine .php except if you are utilizing some other augmentation.

Presently, go to your controller record (Main.php) and compose this code as appeared as follows.

Codeigntor sees 2 

11) Explain controller in CodeIgniter. 

A controller is the delegate among models and perspectives to process the HTTP demand and produces a website page. It is the focal point of each solicitation on your web application.

Think about after URI,

abc.com/index.php/front/

In this URI, CodeIgniter endeavor to discover Front.php record and Front class.

Controller Syntax

controller 1

Take a gander at the above preview, controller's document name is Main.php (the primary letter must be in capitalized), and the class name is Main (the principal letter must be in capitalized).

12) What is the default controller in CodeIgniter? 

The record determined in the default controller stacked as a matter of course when no document name is referenced in the URL. Of course, it is welcome.php which is the primary page to be seen in the wake of introducing CodeIgniter.

With URL

localhost/codeigniter/

Welcome.php will be stacked as there is no document name referenced in the URL.

In spite of the fact that according to your need, you can change the default controller in the record application/config/routes.php.

$route['default_controller'] = ' ';

Here, determine your record name which you need to be stacked as a matter of course.

13) How will you call a constructor in CodeIgniter? 

To utilize a constructor, you have to make reference to the accompanying line of code,

parent::_construct()

14) What is the essential CodeIgniter URL structure? 

Rather than utilizing 'question string' approach, it utilizes a section based methodology.

Its structure is as per the following,

abc.com/class/work/ID

The class speaks to a controller class that should be conjured.

The capacity is the technique that is called.

ID is an extra portion that is passed to controllers.

15) What is an inhibitor of CodeIgniter? 

In CodeIgniter, Inhibitor is a mistake handler class that utilizes local PHP capacities like set_exception_handler, set_error_handler, register_shutdown_function to deal with parse blunders, exemptions, and lethal mistakes.

16) What is the default technique name in CodeIgniter? 

Of course controller dependably calls list technique. On the off chance that you need to call an alternate strategy, at that point compose it in the controller?s document and indicate its name while calling the capacity.

Codeigniter Methods 1

Take a gander at the URL. There is no strategy name is referenced. Consequently, of course record strategy is stacked.

17) Explain the remapping strategy brings in CodeIgniter. 

The Second portion of URI figures out which strategy is being called. On the off chance that you need to abrogate it, you can utilize _remap() strategy. The _remap strategy dependably get called regardless of whether URI is unique. It supersedes the URI. For Example:

open capacity _remap($methodName)

{

in the event that ($methodName === 'a_method')

{

$this->method();

}

else

{

$this->defaultMethod();

}

}

18) What is an assistant in CodeIgniter? By what method can an assistant document be stacked? 

Assistants are the gathering of capacities that are utilized to help the client to perform explicit undertakings.

URL Helpers: used to make the connections.

Content Helpers: utilized for content arranging.

Treats Helpers: utilized for perusing and setting treats.

19) How would you be able to stack different aide documents? 

To stack various aide documents, determine them in an exhibit,

$this->load->helper(

array('helper1', 'helper2', 'helper3')

);

20) Explain the CodeIgniter library. By what method will you load it? 

CodeIgniter gives a rich arrangement of libraries. It is a basic piece of CodeIgniter as it builds the creating pace of an application. It is situated in the framework/library.

It very well may be stacked as pursues,

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

21) How would you be able to make a library in CodeIgniter? 

There are three techniques to make a library,

Making a completely new library

Broadening local libraries

Supplanting local libraries

22) Where is a recently made library put away in CodeIgniter structure? 

It ought to be set in application/libraries organizer.

23) Can you expand local libraries in CodeIgniter? 

Indeed, we can add some all-inclusive usefulness to a local library by including a couple of strategies. It replaces the whole library with your rendition. So it is smarter to broaden the class. Broadening and supplanting is practically indistinguishable with just after special cases.

The class statement must broaden the parent class.

New class name and filename must be prefixed with MY_.

For instance, to extend it to local Calendar, make a document MY_Calendar.php in application/libraries organizer. Your class proclaimed as class MY_Calendar expands CI_Calendar}

24) How would you be able to expand a class in CodeIgniter? 

You need to assemble a document name application/center/MY_Input.php and proclaim your class with Class MY_Input broadens CI_Input {}to expand the local information class in CodeIgniter.

25) What is directing in CodeIgniter? 

Directing is a system by which you can characterize your URLs as indicated by the prerequisite as opposed to utilizing the predefined URLs. Courses can be characterized in two different ways, either utilizing Wildcards or Regular Expressions.

Special cases

There are two sorts of trump cards:

:num−series containing just numbers coordinated.

:any−series containing just characters coordinated.

Ordinary Expression

Ordinary articulations are additionally used to divert courses.

$route['blog'(a-zA-Z0-9]+)'] = 'ladies/social';

You can make your standard articulation to run your URL.

26) Why is URL courses should be arranged? 

There are numerous reasons for which the URL courses are designed.

To improve the quantity of page visits.

To conceal the code complexities from the client.

27) What are the snares in CodeIgniter? 

The Hook is an element in CodeIgniter that gives an approach to change the internal working of the structure without hacking the center documents. It encourages you to execute a content with a specific way inside the CodeIgniter. More often than not, it is characterized in the application/config/hooks.php document.

28) How to empower CodeIgniter snare? 

To empower snare, go to application/config/config.php/document and set it TRUE as appeared as follows,

$config['enable_hooks'] = TRUE;

29) What are diverse kinds of snare focuses in CodeIgniter? 

A rundown of various kinds of snare focuses in CodeIgniter:

post_controller_constructor - It is called following your controller is begun however before any strategy call.

pre_controller - It is called preceding your controller being called. Now, every one of the classes, security checks, and directing have been finished.

post_sytem - It is called after the last page is sent to the program toward the finish of the framework execution.

pre_system - It is called much before the framework execution. Just benchmark and snare class have been stacked now.

cache_override - It empowers you to call your capacity in the yield class.

display_override - It is utilized to send the last page toward the finish of document execution.

post_controller - It is called following your controller is totally executed.

30) What are CodeIgniter drivers? 

These are a specific kind of library that has a parent class and numerous kid classes. These youngster classes approach the parent class, yet not to their kin. Drivers are found in framework/libraries organizer.

31) How to introduce a driver in CodeIgniter? 

To introduce a driver, compose the accompanying sentence structure,

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

Here, class_name is the driver name.

32) How to make a driver in CodeIgniter? 

There are three stages to make a driver:

Making document structure

Making driver list

Making driver(s)

33) How to interface different databases in CodeIgniter? 

To interface more than one database all the while, do the accompanying,

$db1 = $this->load->database('group_one', TRUE);

$db1 = $this->load->database('group_two', TRUE);

34) How would you be able to print SQL proclamation in CodeIgniter show? 

$this>db>insertid();

35) What are CodeIgniter security techniques? 

CodeIgniter security techniques help to make a protected application and procedure input information. The strategies are given beneath:

XSS sifting

CSRF (Cross-site Request Forgery)

Class reference

36) What are the XSS security parameters? 

XSS represents cross-site scripting. Codeigniter contains a cross-site scripting hack anticipation channel. The XSS channel targets techniques to trigger JavaScript or different sorts of suspicious code. On the off chance that it recognizes anything, it changes over the information to character substances.

XSS sifting utilizes xss_clean() strategy to filer information.

$data = $this->security->xss_clean($data);

There is a discretionary second parameter, is_image, which is utilized to test pictures for XSS assaults. At the point when this parameter is set to TRUE, it doesn't restore a modified string. Rather, it returns TRUE if a picture is protected and FALSE on the off chance that it contains malignant data.

in the event that ($this->security->xss_clean($file, TRUE) === FALSE)

{

/document flopped in xss test

}

37) How can the CodeIgniter be kept from CSRF? 

There are the different ways by which, we can keep CodeIgniter from CSRF. The most utilized technique is utilizing the shrouded field in each page of the site. The concealed field is put away in the client's session. The documented is changed with each HTTP demand. The client can be distinguished in its each solicitation to the site. The concealed esteem is constantly contrasted and the one spared in the session. In the event that it is the equivalent, the solicitation is substantial.

38) How would you be able to empower CSRF? 

You can empower security by altering config.php document and setting it to

To empower CSRF own the accompanying expression TRUE from FALSE in application/config/config.php document.

$config['csrf_protection'] = TRUE;

39) What is CSRF assault in CodeIgniter? 

A CSRF assault powers a signed on injured individual's program to send a fashioned HTTP demand, including unfortunate casualty's session treat and other verification data, to a web application.

For instance, assume you have a site with a structure. An assailant could make a counterfeit structure on his site. This structure could contain concealed sources of info and vindictive information. This structure isn't sent to the assailant's site, indeed, it goes to your site. Imagining that the structure is certifiable, your site procedure it.

Presently assume that the assailant's structure point towards the cancellation structure in your site. On the off chance that a client is signed in and diverted to the assailant's site and after that play out the hunt, his record will be erased without knowing him. That is the CSRF assault.

40) What is a token technique in a CSRF assault? 

To shield from CSRF, we have to associate both HTTP demands, structure solicitation and structure accommodation. There are a few different ways to do this, yet in CodeIgniter concealed field is utilized which is known as the CSRF token. The CSRF token is an irregular esteem that changes with each HTTP demand sent.

With each solicitation, another CSRF token is created. At the point when an article is made, name and estimation of the token are set.

$this->csrf_cookie_name = $this->csrf_token_name;

$this->_csrf_set_hash();

The capacity for it is,

work _csrf_set_hash()

{

on the off chance that ($this->csrf_hash == '')

{

on the off chance that ( isset($_COOKIE[$this->csrf_cookie_name] ) AND

$_COOKIE[$this->csrf_cookie_name] != '' )

{

$this->csrf_hash = $_COOKIE[$this->csrf_cookie_name];

} else {

$this->csrf_hash = md5(uniqid(rand(), TRUE));

}

}

return $this->csrf_hash;

}