Codeigniter Interview Questions for Freshers

What is the MVC pattern of Codeigniter?

Codeigniter follow the MVC architecture. Using MVC you can separate logic from presentation.
Model: Contains all the database function.Using a model you can insert, update, delete the data from the database.
View: Generally, view on 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”.
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.

Describe what are the features of Codeigniter?

Below are the important features of Codeigniter:

  • Codeigniter is an open-source framework and free to use.
  • It is excessively light weighted.
  • It follows the MVC architecture that allows separation between logic and presentation.
  • Codeigniter generates URLs which are clean and search engine friendly.
  • Codeigniter has full-featured database classes and support for several platforms.
  • It is faster than other frameworks.

How to configured base URL in Codeigniter?

In Codeigniter, the base URL is configured in application/config/config.php file.
The base URL can be configured in the $config array with key “base_url” as given below −

How to configured database in Codeigniter?

In codeigniter,database can be configured in application/config/database.php file.
Codeigniter provided a multidimensional array which can set up a database for the different environments like development and production.
These configuration settings are stored in the array which is given below −

 

Describe Codeigniter Architecture?

Ans: According to the technical point of view, CodeIgniter is dynamically instantiation (light-weighted),
loosely coupled (components count very less on each other) and has a component singularity
(each class and functions are barely focused towards their purpose).

In Codeigniter, what is the default method name?

Ans: In Codeigniter, By default, always index method is being called by the controller. To call a different method, write it in the controller’s
file and specify its name while calling the function.

In Codeigniter, define Helper? How to load a Helper file?

Ans: A group of methods in a particular category which boosts you to perform specific functions is called Helper.
In CodeIgniter, helpers are like:
1: Cookies Helpers: set and read cookies.
2: Text Helpers: perform various text formatting routines.
3: URL Helpers: helping in creating links.
Use the bellow command to load helper file:
$this->load->model(‘ModelName’);

In Codeigniter,how to access config variable?

In codeigniter,using following code to access config variable:
$this->config->item(‘variable name’);

In codeigniter how to unset session?

In codeigniter,writing the following code to unset session:
$this->session->unset_userdata(‘somename’);

In Codeigniter describe Application Flow Chart?

The following graphic illustrates how data flows throughout the system:
CodeIgniter application flow:
1: The index.php provides the front controller, which initializing the base resources needed to run CodeIgniter.
2: The Router inspects the HTTP request to include what should be done with it.
3: If a cache file exists, bypassing the normal system execution, that file is sent directly to the browser.
4: Before the application controller is loaded, the HTTP request and any user who submitted data are refined for security.
5: The Controller loads the core libraries, helpers, model and any other resources which need to process the specific request.
6: The finalized View is carried out then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on the following requests it can be served.

In Mysql, how to get Random Records using Codeigniter?

Ans: To get the random record in MySql, We can use this:

 

In Codeigniter what are the Security Parameter for XSS?

  1. It has a cross-site scripting hack prevention filter.
  2. Using this filter either runs automatically or as per item basis,to filter all POST and COOKIE data that come across.
  3. The XSS filter will target the frequently used methods to trigger JavaScript or other types of code that attempt to steal cookies or other malicious activity.
  4. If it identifies any doubtful thing or anything excluded is detected, it will convert the data to character entities.

In Codeigniter, how many types of messages can a user log?

In Codeigniter there are 3 types of messages are present:
1: Error messages->Actual errors such as user error or PHP errors.
2: Debug messages->Debug messages assist in debugging.
Example: You could log this as debugging if a class has been initialized.
3: Informational messages: Lowest priority messages comes under Informational messages. In other words, only giving information regarding some process.

In Codeigniter, in which directory logs are saved?

In logs/directory, by default, all logs are stored. To facilitated error logging the user must set the “threshold” for logging in application/config.php and logs must be writable.

In Codeigniter, in which files routes are defined?

In Codeigniter, All routing rules are defined in application/config/routes.php file.

In Codeigniter, what are the resources that can be autoloaded?

These are the list of resources that are autoloaded automatically:
1: In libraries/directory, classes are found.
2: In helpers/directory, helper files are found.
3: In system/language/directory, languages files are found.
4: In config/directory, custom config files are found.
5: In models/folder, models are found.
In Codeigniter, to autoload resources, open application/config/autoload.php file and add the item that the user wants to load to the autoload array.

Explain ORM? What is the ORM for Codeigniter?

ORM stands for object-relational-mapping.
It is a programming technique for reorganizing the data between incompatible type systems using object-oriented programming languages.
Below is the ORM’s supported Codeigniter framework.
1:     Data mapper
2:     Doctrine
3:     Gas ORM

In Codeigniter how to delete a record?

Ans: In Codeigniter, using delete function to delete a record

 

In Codeigniter, how the user can use and load Codeigniter libraries?

In codeigniter,library can be loaded by using $this->load->library(‘library_name’);

 

In Codeigniter what is the use of is_cli()method?

Ans: In Codeigniter, using is_cli()method to check request is from the command line or not.
If the application is run through the command line, it returns TRUE and it returns FALSE, if not.

In Codeigniter, how to fetch the last inserted id?

In codeigniter,to fetch the last inserted id using insert_id() function.

 

In Codeigniter, define Sessions and how to create and read a session?

1: Session class confesses to maintain a user’s “state” and track their activity during they are browsing your website.
2: Using session, we need to load the class of the session to the controller.
3:In Codeigniter,to load the session using $this->load->library(‘session’); method.
4:After loading is complete,using $this->session,session library object will be available.

Creating a session:
In Codeigniter,a session can be created by using set_userdata() method of Session’s Class.set_userdata() method holds an associative array that containing
data, which is user want to add in session.

 

Reading a session:
In codeigniter,a session can be read the data by using $this->session->userdata(); method of session class.

 

In Codeigniter, how to add and load a model?

Ans:In codeigniter,generally model will be loaded by using $this->load->model(‘model_name’); method.
After loading will be complete, the user will access its methods using an object with the same name as your controller:

 

In Codeigniter, how error handling works?

Ans: Using the functions, Codeigniter builds error reporting into the applications.
Codeigniter has an error logging class which grants error and debugging messages to be saved as text files.
These are the functions which are explained below:

1:       show_error(‘message’ [, int $statuscode= 500 ] )
Using template application/errors/errorgeneral.php file, it will display the error message given to it.
2:       show_404(‘page’ [, ‘logerror’])
Using template application/errors/error404.php file, it will display the 404 error message given to it.
3:       log_message(‘level’, ‘message’)
It writes 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.

What are the features for sending an email in Codeigniter?

Ans: In Codeigniter, sending email is most easier.
These are the features for sending an email:

  • 1: Multiple recipients
  • 2:HTML or Plaintext email
  • 3: Word wrapping
  • 4: Attachments
  • 5: BCC Batch Mode
  • 6: Email Debugging tools
  • 7: Multiple Protocols − Mail, Sendmail, and SMTP
  • 8: TLS and SSL Encryption for SMTP
  • 9: CC and BCCs
  • 10: Priorities

How to send an email, using Codeigniter?

Codeigniter is used to send an email,using $this->load->library(’email’); code to load the email library.
After loading the email library, these are the functions which are used to set basic elements to send an email.

  1. form()->It is used to set from where the email is being sent
    Example:$this->email->from(‘your@example.com’, ‘Your Name’);
  2. to()->It is used to whom the email is being sent.
    Example:$this->email->to(‘someone@example.com’);
  3. subject()->It is used to set the subject of the email.
    Example:$this->email->subject(‘Email Test’);
  4. message()->It is used to set the message of the email.
    Example:$this->email->message(‘Testing the email class.’);
  5. send()->It is used to execute to send an email.
    Example:$this->email->send();

In codeigniter,define flashdata and how to add and retrieve it?

After the development of web application, only one time we need to store some data and then we remove it.
Example: To display some error message.

 

Advertisements