Top 11 CodeIgniter Interview Questions and Answers
Here, you will come across some of the most frequently asked questions in CodeIgniter job interviews which will help you in your interview preparation.
Let's have a look at some of the most popular and significant CodeIgniter questions and answers:
Interview Questions
Most Essential And Frequently Asked Interview
Questions And Answer
CodeIgniter
Q.1. List Databases supported By Codeigniter Frameworks
Ans.:Codeigniter | List Databases supported By Codeigniter
Following Databases are supported by Codeigniter Frameworks:
Database Name | Drivers to support Codeigniter |
MySQL | MySQL (deprecated), MYSQLI and PDO drivers |
Oracle | oci8 and PDO drivers |
PostgreSQL | Postgre and PDO drivers |
MS SQL | MsSQL, Sqlsrv (version 2005 and above only) and PDO drivers |
SQLite | SQLite (version 2), sqlite3 (version 3) and PDO drivers |
CUBRID | Cubridand PDO drivers |
Interbase/Firebird | iBase and PDO drivers |
ODBC |
ODBC and PDO drivers (you should know that ODBC is actually an abstraction layer) |
Q.2. In which files routes are defined in Codeigniter?
Ans.:Codeigniter | routes
Routing rules are defined in your application/config/routes.php file.
View DetialsQ.3. What is helpers in CodeIgniter and how to load helper file?
Ans.:CodeIgniter | What is helpers | Load helper file
Helper is simply a collection of function in a particular category which helps you with tasks. The helper file can be loaded in controller constructor, some specific function, or in application/config/autoload.php file
Adding helper in the controller:
$this->load->helper('name');View Detials
Q.4. How to set timezone in codeigniter?
Ans.:Codeigniter | Set timezone
To set default timezone in Codeigniter, you can add the date_default_timezone_set() function in your application/config.php or index.php file.
date_default_timezone_set('your timezone');View Detials
Q.5. How to set or get config variables in Codeigniter?
Ans.:Codeigniter | SET or GET config variables
The config set_item() & item() functions are work for SET and GET a config variable in codeigniter
View DetialsQ.6. What is the default URL pattern used in Codeigniter framework?
Ans.:Codeigniter | The default URL pattern
In CodeIgniter, URLs are designed to be search-engine and user-friendly. CodeIgniter uses a segment-based approach rather than using a "query string" based approach.
http://www.example.com/user/edit/rakesh
The default URL pattern in CodeIgniter consists of 4 main components. They are:
Server name | example.com |
Controller | user |
Action or method | edit |
Parameter | Ramesh |
Q.7. How many types of messages can you log in Codeigniter?
Ans.:Codeigniter | Types of error logging
There are three message types in Codeigniter:
Error Messages | These are actual errors, such as PHP errors or user errors. |
Debug Messages | These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info. |
Informational Messages. | These are the lowest priority messages, simply giving information regarding some process. |
Q.8. How to include image, css and js file in codeigniter?
Ans.:Codeigniter | Include image, CSS, and js file
In Codeigniter, we need to load URL helper in the controller and then use the base_url() function to load the resources.
// loading script <script type='text/javascript' src="<?php echo base_url('js/jquery.min.js'); ?>"></script> // loading image <img src="<?php echo site_url('images/myimage.jpg'); ?>" />View Detials
Q.9. How to remove index.php in codeigniter?
Ans.:Codeigniter | Remove index.php from URL in Codeigniter?
The file index.php is the root file of Codeigniter. it contains setting code for CodeIgniter. So, when we redirect to other pages the URL comes with index.php which looks ugly and also not good for SEO points of view. we can simply say that the URL is not user friendly.
The URL looks like this:
http://localhost/codeigniter/index.php/welcome/demo
OR
http://www.example.com/index.php/welcome/demo
Now for removing the index.php from the URL, we need to do some simple step:
Step1: Open the config.php file located in the "/application/config" folder. Find and modify the below code.
// Find the below codes
$config['index_page'] = "index.php"
$config['uri_protocol'] = "AUTO"
// replace with these codes
$config['index_page'] = ""
$config['uri_protocol'] = "REQUEST_URI"
Step2: Create a .htaccess file in the project root directory. The .htaccess file is used to modify or change the configuration of the apache server. The below code tells the apache server to ignore index.php in requested URI. Copy the below code in .htaccess file.
It should be located as:
your_project_name folder > .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Q.10. what is Cross-site scripting?
Ans.:Cross-site scripting (XSS)
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications. XSS enables attackers to inject client-side script into web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same-origin policy.
Q.11. What do you mean by the csrf_token?
Ans.:The csrf_token is used for protection against Cross-Site Request Forgeries. This kind of attack takes place when a malicious website consists of a link, some JavaScript, or a form whose aim is to perform some action on your website by using the login credentials of a genuine user.