CodeIgniter is an open source and powerful MVC(Model-View-Controller) based framework used for developing web applications on PHP.
It is loosely based on MVC pattern and similar to Cake PHP. CodeIgniter contains libraries, simple interface and logical structure to access these libraries, plug-ins, helpers and some other resources which solve the complex functions of PHP more easily maintaining high performance.
It simplifies the PHP code and brings out a fully interactive, dynamic website at a much shorter time.
The framework is available as open-source software under the MIT License and follows the model-view-controller (MVC) structure for web development.
Q2. List some features provided by CodeIgniter?
It is an open source framework and free to use.
It is extensible. You can easily extend the system by using your libraries, helpers.
It is extremely light weighted.
Nearly zero configuration.
Excellent documentation.
Strong Security.
Simple solutions over complexity.
It has full featured database classes and support for several platforms.
It is based on the Model View Controller (MVC) pattern.
Q3. What are hooks in CodeIgnitor?
CodeIgniter’s hooks will provide a way to change the internal workings or framework functionalities without any need for hacking the core files. It permits script execution with a particular path within the CodeIgniter.
We can globally enable/disable the hooks feature.
Q4. What are different types of hook points in CodeIgniter?
pre_system
pre_controller
post_controller_constructo
post_controller
display_override
cache_override
post_system
Q5. How do you check the version of CodeIgniter?
In system/core/CodeIgniter.php, check CI_VERSION constant value define(‘CI_VERSION’, ‘3.0.6’);
echo CI_VERSION;
Q6. difference between helper and library in CodeIgniter?
Helper
Library
It is not written in object-oriented format.
It is written in an object-oriented format.
All built-in helper file names are suffixed with a word _helper
All built-in library files do not have a specific suffix.
It can be called in the same manner you call PHP functions.
You must create an object of the class to call library functions by using the $this->library_name->method()
Q7. What is routing in CodeIgniter?
Routing is a technique used in CodeIgniter, by which you can define your URLs based on the requirement instead of using the predefined URLs.
So, whenever there is a request made and matches the URL pattern defined by us, it will automatically direct to the specified controller and function.
The file is located at application/config/routes.php
Q8. What are drivers in CodeIgniter?
A driver is a type of library that has a parent class and multiple child classes. These child classes can access their parent class, but they can’t access their siblings.
Drivers can be found in the system/libraries folder.
Q9. Why CodeIgniter is called a loosely based MVC framework?
Because it does not follow a strict MVC pattern during application creation. It is not important to create a model, we can use only view and controllers for creating an application. In addition, one can modify CodeIgniter to utilize HMVC(Hierarchical Model View Controller) as well.
Q10. List Databases supported By Codeigniter Frameworks?
MySQL.
PostgreSQL.
SQLite.
Interbase/Firebird.
Oracle.
ODBC.
MS SQL.
Q11. How to add/load a model in CodeIgniter?
$this->load->model(‘model_name’);
Q12. How do you autoload a model in codeigniter?
application/config/autoload.php file and add your model to the autoload array.
Q13. Explain the folder structure of CodeIgniter
Application
cache
Config
Controllers
core
errors
helpers
hooks
language
libraries
logs
models
third-party
views
system
core
database
fonts
helpers
language
libraries
Q14. What is inhibitor are Codeigniter?
An inhibitor is an error handling class in Codeigniter.
It uses PHP ‘s native functions like register_shutdown_function , set_exception_handler, set_error_handler to handle parse errors, exceptions, and fatal errors.
Q15. What are the advantages of CodeIgniter?
Built-in libraries
Data abstraction
Security
Active Developer Community
Easy to Use
Collaboration with Expression Engine
Immigration Features
Q16. Explain MVC in CodeIgniter
Model - The Controller manages models. It represents your data structure. Model classes contain functions through which you can CRUD (Create, Read, Update and Delete) operations in your database.
View - View is the information that is presented in front of users. It can be a web page or parts the page like header and footer. In this part you can write your HTML, CSS and Javascript code.
Controllers - Controller is the intermediary between models and view to process HTTP request and generates a web page. All the requests received by the controller are passed on to models and view to process the information. It works like a Bridge to pass data from model to view and view to model.
Q17. How can you load a view in CodeIgniter?
$this->load->view('page_name');
Q18. What is the architecture of CodeIgniter?
There are 3 key details about the architecture of CodeIgniter -
It is dynamically instantiated making it extremely lightweight
The components are mostly independent, making it loosely coupled
Every class and function focuses on its own purpose, giving it component singularity
Q19. Please explain about data flow in CodeIgniter?
index.php is the default file of CodeIgniter. This file initializes the base resources.
The router determines what should be done with the information.
If the requested cache file exists, then the information is moved directly to the browser and ignores the further processes.
The application controller will load the models, libraries, helpers, plugins, and scripts required according to the request.
A view is used for fetching the data from the application controller that will be represented to the user, and they pass the data to the caching file to the fastest access for future requests.
Q20. How to define a default controller in CodeIgniter?
You can set this default controller in application/config/routes.php
$route[‘default controller’] = ‘your_controller’;
Q21. What is meant by a library?
The essential part of a CodeIgniter framework is its libraries. It provides a rich set of libraries, which indirectly increase the speed of developing an application. The system library is located at system/libraries.
Class name is the name of the library that we want to load.
To load a library in CodeIgniter, you have to include the below code inside a controller: $this->load->library(‘class_name’);
Q22. How can you remove index.php from URL in Codeigniter?
Open config.php and replaces
$config['index_page'] = "index.php" to $config['index_page'] = "" and
$config['uri_protocol'] ="AUTO" to $config['uri_protocol'] = "REQUEST_URI"
Change your .htaccess file to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP} off
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
CSRF(Cross-Site Request Forgery) token is a randomly generated value that gets modified with every HTTP request sent by webform.
To protect from CSRF we need to connect both the HTTP requests, form request and form submission. There are several ways to do this, but in CodeIgniter hidden field is used which is called CSRF token. The CSRF token is a random value that changes with every HTTP request sent.
When CSRF token is inserted in the website form, it also gets saved in the user's session. When the form is submitted, the website matches both the token, the submitted one and one saved in the session. If they match, request is made legitimate. The token value changes each time the page is loaded, which makes it tough for the hackers to guess the current token.
Q24. What is the difference between Laravel and CodeIgniter?
Laravel
CodeIgniter
It is object-oriented.
It is relational object-oriented.
Follows MVC structure of filing with a command-line tool known as Artisan.
Follows the MVC structure but it provides easier boarding based on object-oriented programming.
It comes along with a built-in module.
It does not come with a built-in module.
Supports Explicit routing.
Supports both Explicit and Implicit routing.
Provide their own official documentation which is very helpful.
Provides a lot of built-in functionality
Q25. How do you load a helper file?
$this->load->helper(‘name’);
Q26. Explain the remapping method calls in CodeIgniter?
The 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.
class NormalController extends Your_Base_Class
{
public function __construct()
{
parent::__construct();
// code you want to put here
}
// your methods name go here
}
Q32. Why is URL routes need to be configured?
To improve the number of page visits.
To hide the code complexities from the user.
Q33. What is the security parameter for XSS in CodeIgniter?
Codeigniter has got a Cross-Site Scripting(XSS) hack prevention filter. This filter either automatically runs or you can run it based on item, to filter all data related to POST and COOKIE.
This filter will prevent any malicious JavaScript code or any other code that attempts to hijack cookie and do malicious activities. To filter data through the XSS filter, use the xss_clean() method
The XSS filter will target the frequently used methods to trigger JavaScript code or other types of code that attempt to hijack cookies or do any other malicious activity. If it identifies anything suspicious or anything disallowed is encountered, then it will convert the data to character entities.
$data = $this->security->xss_clean($data);
Q34. How do you enable hooks in CodeIgniter?
In application/config/config.php file and switch the following setting to ‘TRUE’ as shown below.
$config[‘enable_hooks’] = TRUE;
Q35. What is the method to link multiple databases in CodeIgniter?
$db1 = $this->load->database(‘group_one’, TRUE);
$db1 = $this->load->database(‘group_two’, TRUE);
Q36. What are security methods in CodeIgniter?
CSRF (Cross-site Request Forgery)
XSS filtering
Class reference
Q37. What are Sessions In CodeIgniter? How to read, write or remove session in CodeIgniter?
In CodeIgniter Session class allows you maintain a user’s “state” and track their activity while they are browsing your website.
In order to use session, you need to load Session class in your controller.
$this->load->library(‘session’); method is used to sessions in CodeIgniter
$this->session->userdata(); method of session class to read session data in CodeIgniter.
Q40. How to check a field or column exists in a table or not in Codeigniter?
if ($this->db->field_exists('field_name', 'table_name'))
{
// some code...
}
Q41. What is an ORM in Codeigniter?
Object-relational mapping (ORM) is programming technique for converting data between incompatible type systems using object-oriented programming languages.
DataMapper
Doctrine
Gas ORM
Q42. In which directory logs are saved in Codeigniter?
By default, all logs in Codeigniter are stored in logs/ directory.
To enable error logging you must set the threshold for logging in application/config/config.php.
$config['log_threshold'] = 1;
Q43. How many types of messages can you log in Codeigniter?
Error Messages
Debug Messages
Informational Messages
Q44. How to create a driver in CodeIgniter?
Making file structure
Making driver list
Making driver(s)
Q45. List all the auto loadable resources in CodeIgniter?
libraries
config
helpers
language
models
Q46. How to print SQL query in CodeIgniter model?
echo $this->db->last_query();
Q47. How can we get last inserted ID in codeigniter?
echo $this->db->insert_id();
Q48. 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 name, controller function name and finally function parameters to accesses the URL pattern.
Q49. 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 stored in the application/models folder.
class ModelName extends CI_Model
{
public function functionName()
{
}
}
Q50. What do you mean by the views in 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.
Q51. 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.
class ControllerName extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function functionName()
{
}
}
Cookie Policy
This website uses cookie or similar technologies, to enhance your browsing experience and provide personalised recommendations. By continuing to use our website, you agree to our Cookie Policy.