Top 10 CodeIgniter Interview Questions & Answer

Top 10 CodeIgniter Interview Questions & Answer
IT & Software

1. What is Codeigniter Framework?

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

Nows a days, Model View Controller(MVC) is the most popular design pattern in software development.

Codeigniter Framework provide predefine function and Library which are used for application development. codeigniter Framework also support HMVC.

 

2. What is a helper in codeigniter and how it is loaded? Explain different type of helpers?

Helpers is collection of functions which help us with different tasks as name suggested. Every helper function is used to performs specific task with no dependence on other functions.

CodeIgniter provide various types of helper class like url_helper, captcha_helper ,email_helper. All these helpers are located in

system/helper

By default CodeIgniter does not load any Helper files. First step is to be load Helper. After loaded it is available in all controller and views.

To load helpers : 

$this->load->helper('name');

To load multiple helpers : 

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

 

Different types of helpers are as follows:

  • FILE HELPER: It helps to deal with the file.
  • TEXT HELPER: This is used to perform various text formatting routines.
  • FORM HELPER: It helps in creating form elements.
  • COOKIE HELPER: set and real cookies 
  • URL HELPER: It assists in creating links.

 

It’s appropriate in the following situations to create a project with CodeIgniter. 

  1. Small learning curve. 
  2. Situations where a framework with a small footprint is needed. 
  3. It’s a framework with zero configuration.
  4. It’s a framework which doesn’t require to stick to strict coding rules. 
  5. Provides high performance and simple coding structure. 
  6. It’s a framework which doesn’t use the command line. 
  7. It provides built-in protection against CSRF and XSS attacks.

3. What is different between library and helper?

LIBRARY 

  • The Library is a class. So, the user needs to make an instance of the class to use it.
  • Libraries are located under System/Libraries.
  • It is object-oriented.
  • A library can be loaded using $this->load->library (‘library name’).
  • To call library functions, the user needs to create an object of the class.

HELPERS 

  • A Helper is a file that has PHP functions.
  • Helpers are located under System/Helpers.
  • These are not written in an object-oriented format, hence the user can simply call helper functions.
  • A Helper can be loaded using $this->load->Helper (‘helper name’)
  • Helpers can be called in the same way you call PHP functions.

 

4. How would you use CodeIgniter to connect to multiple databases in a single application?

CodeIgniter allows for multiple database connections within a single application by defining each connection in the application’s database configuration file. To do this, you create an array with the database settings for each connection.

Here is an example of how to define two databases:

$db['default'] = array(

'dsn' => '',

'hostname' => 'localhost',

'username' => 'root',

'password' => '',

'database' => 'database_name1',

'dbdriver' => 'mysqli',

);

$db['second_db'] = array(

'dsn' => '',

'hostname' => 'localhost',

'username' => 'root',

'password' => '',

'database' => 'database_name2',

'dbdriver' => 'mysqli',

);

 

5. Explain about routing in codeigniter .

CodeIgniter has a userfriendly URI routing rule so that we can re-route URL easily . There is a one-to-one relationship between a URL string and its corresponding controller class and its methods.

Routing is a technique through which we can converts SEO friendly URLs into a server code format that easily understandable.

We can manage these from  routes.php file at the located in application/config

 

6. How to remove index.php from URL in

You can follow these given steps to remove index.php from URL in Codeigniter.

 

1. Please open config.php

2. change from $config['index_page'] = "index.php" to $config['index_page'] = "";

3. Update also from $config['uri_protocol'] ="AUTO"; to $config['uri_protocol'] = "REQUEST_URI";

4. Put this code in your htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

 

7. What is Hooks in CodeIgniter?

Hooks are the special feature of CodeIgniter that allows changing the inner functionality of the framework without making any change in core files of the framework. The hooks are prescribed in application/ hooks.php/config

 

These are the hook points available in Codeigniter:

  • pre_system - It is called during system execution.
  • pre_controller - This is called immediately before calling the controllers.
  • post_controller - constructor - This method is called instantly after the controller is instantiated but before calling any method.
  • post_controller - The post_controller hook is called immediately after the controller is fully executed.
  • display_override - This hook overrides the _display() method.
  • cache_override - This hook is used when there is a need to call our method instead of the method from Output Library called _display_cache(). It permits us to use your own cache display mechanism.
  • post_system - This hook is called when the final page is sent to the browser after the final execution.

 

8. What is session in codeigniter?

Sessions allows us to maintain the user “states” and helps to track user activity. In codeIgnitor session can be loaded with $this->load->library(‘session’);  post loading session library object we can use with $this->session.

To read the session data : $this->session->userdata(‘key’). 

Session data can also be get by $this->session->item To create a session in codeIgnitor: Session’s Class set_userdata() method is used to create a session in CodeIgniter. This method takes an associative array containing your data that you want to add in session.

To add userdata one value at a time, set_userdata() also can be use with syntax:

$this->session->set_userdata('some_name', 'some_value');

To remove session data : It can be done with unset a particular key 

$this->session->unset_userdata('some_key');

Unset array of item keys : 

$array_items = array('username', 'email'); $this->session->unset_userdata($array_items);

 

9. List the databases supported by Codeigniter Frameworks.

The databases supported by Codeigniter Frameworks are:

  • MySQL (5.1+) via the MySQL (deprecated), MySQL and PDO drivers
  • Oracle via the oci8 and PDO drivers
  • PostgreSQL via the Postgre and PDO drivers
  • MS SQL via the MsSQL, Sqlsrv (version 2005 and above only) and PDO drivers
  • SQLite via the SQLite (version 2), sqlite3 (version 3) and PDO drivers
  • CUBRID via the Cubridand PDO drivers
  • Interbase/Firebird via the iBase and PDO drivers
  • ODBC via the ODBC and PDO drivers

 

10. Explian the MVC structure of codeigniter.

MVC stands for MODEL VIEW CONTROLLER. Model View Controller separates application logic from the presentation layer. It helps web pages to contain minimum scripting.

MODEL: It is used to represent data structures. Model classes constitute functions that help to insert, retrieve, and update information in the database.

CONTROLLER: It acts as an intermediary between the view, model, or any other resource to process HTTP requests. The Controller controls the whole application by URI.

VIEW: It represents the information that is being presented to the user. In CodeIgniter, a View could be a simple or complex webpage. The web page contains a header, footer, sidebar, etc. A view cannot be called directly.

 

  • To Share this Blog, Choose your plateform


Leave a Reply

Your email address will not be published. Required fields are marked *


Add Review

Rating:


Trending Blogs

Dive into our trending blog for fresh insights on lifestyle, wellness, and tech. Stay inspired with engaging content that sparks creativity and keeps you informed on the latest happenings! Click to View All Blogs

Important Interview Questions and Answers

Key IT and software interview topics include coding challenges, system design, algorithms, and troubleshooting to showcase technical skills and problem-solving abilities.
Click to View All Interview Question and Answer

50+ Interview Question

PHP (Hypertext Preprocessor) is an open-source server-side scripting language used for dynamic web development, enabling easy integration with HTML and various databases. Start Now

50+ Interview Question

CodeIgniter is a lightweight PHP framework designed for rapid web application development. It follows the MVC pattern, providing a simple and elegant toolkit for developers. Start Now

50+ Interview Question

Laravel is a popular PHP framework that simplifies web application development. It follows the MVC architecture, offering elegant syntax, built-in tools, and strong community support. Start Now

50+ Interview Question

MySQL is an open-source relational database management system that uses SQL for data manipulation. It’s widely used for web applications, offering reliability, scalability, and flexibility. Start Now

50+ Interview Question

JavaScript is a versatile, high-level programming language primarily used for creating interactive web pages. It enables dynamic content and enhances user experience in browsers. Start Now

50+ Interview Question

jQuery is a fast, lightweight JavaScript library that simplifies HTML document manipulation, event handling, and animation, making it easier to develop interactive web applications. Start Now

50+ Interview Question

Object-Oriented Programming (OOP) is a programming paradigm based on objects, encapsulating data and behaviors. It promotes code reusability, inheritance, and polymorphism for better software design. Start Now

50+ Interview Question

AJAX (Asynchronous JavaScript and XML) is a web development technique that enables asynchronous data loading, allowing web pages to update dynamically without reloading, enhancing user experience. Start Now

50+ Interview Question

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy to read and write. It is widely used for data exchange in web applications. Start Now

50+ Interview Question

React.js is a popular JavaScript library for building user interfaces. It uses a component-based architecture, enabling efficient rendering and development of dynamic, interactive web applications. Start Now

50+ Interview Question

Node.js is a JavaScript runtime built on Chrome's V8 engine, enabling server-side development. It allows for building scalable network applications with event-driven, non-blocking I/O. Start Now

50+ Interview Question

Python is a high-level, versatile programming language known for its readability and simplicity. It's widely used in web development, data analysis, machine learning, and automation. Start Now

50+ Interview Question

C is a high-level programming language known for its efficiency and portability. It provides low-level memory access, making it ideal for system programming and embedded applications. Start Now

50+ Interview Question

An operating system (OS) is software that manages computer hardware and software resources, providing essential services for programs and enabling user interaction with the system. Start Now

50+ Interview Question

Java is a popular, high-level programming language known for its portability, object-oriented design, and ability to run on any device with a Java Virtual Machine (JVM). Start Now

50+ Interview Question

A data structure is a way to organize and store data efficiently for easy access and manipulation, such as arrays, linked lists, trees, and graphs. Start Now