CodeIgniter is an open-source software rapid development web framework, for use in building dynamic web sites with PHP. CodeIgniter is popular model–view–controller (MVC) development pattern. CodeIgniter is most often noted for its speed when compared to other PHP frameworks. Today mostly web development happens in CodeIgniter framework. In PHP interview a lot of questions are asked from CodeIgniter. Here we are listing most popular CodeIgniter Interview Questions with Answers.
1. What is Codeigniter?
Codeigniter is the most popular open source PHP framework. It is very simple and lightweight. It can be used to develop any kind of web project from small website to large scale of application.
2. What are the most prominent features of CodeIgniter?
A list of most prominent features of CodeIgniter:
It is an open source framework and free to use.
It is extremely light weighted.
It is based on Model View Controller (MVC) pattern.
It has full featured database classes and support for several platforms.
It is extensible. You can easily extend system by using your own libraries, helpers etc.
Excellent documentation.
Security and XSS Filtering
File uploading, session management, pagination, data encryption
Flexible URI Routing
Zip encoding class
Error logging
Full page caching
Localization
3. Explain the folder structure of CodeIgniter.
If you download and unzip CodeIgniter, you will get the following file structure/folder structure:
Application
cache
Config
Controllers
core
errors
helpers
hooks
language
libraries
logs
models
thirdparty
views
system
core
database
fonts
helpers
language
libraries
4. How to access config variable in codeigniter?
[code] $this->config->item('variable name'); [/code]
5. How to unset session in codeigniter?
[code] $this->session->unsetuserdata('somename'); [/code]
6. How do you get last insert id in codeigniter?
[code] $this->db->insertid(); [/code]
7. Why use Hooks in Codeigniter
Hooks are the special feature of Codeigniter that allows to change the inner functionality of framework without making any change in core files of framework. The Hooks are defined in application/config/hooks.php.
8. What are different types of hook points in CodeIgniter?
A list of different types of hook points in CodeIgniter:
post_controller_constructor
pre_controller
post_sytem
pre_system
cache_override
display_override
post_controller
9. How can you load a view in CodeIgniter?
View can't be accessed directly. It is always loaded in the controller file. Following function is used to load a view page:
[code] $this->load->view('page_name'); [/code]
10. What is routing in Codeigniter?
Instead of accessing files directly from browser, Routing enables to serve files differently. Routing is an important part of Codeigniter that enables to customize default URL pattern according to requirement to use your own and it redirect automatically to matched URL pattern by specified controller and function.
11. How to load Model in CodeIgniter?
Models are PHP classes that are designed to work with information in your database. In CodeIgniter, Model classes are stored in your application/models/ folder. The models will typically be loaded and called from within your controller functions. To load a model you will use the following function:
[code] $this->load->model('Model_name'); [/code]
12. What are the Helpers in CodeIgniter?
The Helpers are the group of functions in a specific category that helps to perform particular functions. There are many helpers in CodeIgniter that you can use according to your requirement. The major CodeIgniter helpers are URL Helpers that assist in creating link, Form Helpers that help you create form elements, Text Helpers to perform various text formatting routines, Cookie Helpers to set and read cookies, File Helpers to help you deal with files etc.
13. List out different types of hook point in Codeigniter?
Different types of hook point in Codeigniter includes
post_controller_constructor
pre_controller
post_sytem
pre_system
cache_override
display_override
post_controller
14. Mention what are the security parameter for XSS in CodeIgniter?
Codeigniter has got a cross-site scripting hack prevention filter. This filter either runs automatically or you can run it as per item basis, to filter all POST and COOKIE data that come across. The XSS filter will target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it detects any suspicious thing or anything disallowed is encountered, it will convert the data to character entities.
15. Explain how you can link images/CSS/JavaScript from a view in code igniter?
In HTML, there is no Codeigniter way, as such it is a PHP server side framework. Just use an absolute path to your resources to link images/CSS/JavaScript from a view in CodeIgniter
/css/styles.css
/js/query.php
/img/news/235.gpg
16. Explain what is inhibitor in CodeIgniter?
For CodeIgniter, inhibitor is an error handler class, using the native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.
17. Mention what is the default URL pattern used in Codeigniter framework?
Codeigniter framework URL has four main components in default URL pattern. First we have the server name and next we have the controller class name followed by controller function name and function parameters at the end. Codeigniter can be accessed using the URL helper. For example http://servername/controllerName/controllerFunction/parameter1/parameter2.
18. Explain how you can extend the class in Codeigniter?
To extend the native input class in CodeIgniter, you have to build a file named application/core/MY_Input.php and declare your class with
[code] Class MY_Input extends CI_Input {
} [/code]
19.How can you load multiple helper files?
To load multiple helper files, specify them in an array,
[code] $this->load->helper(
array('helper1', 'helper2', 'helper3')
); [/code]
20. Explain how you can prevent CodeIgniter from CSRF?
There are several ways to protect CodeIgniter from CSRF, one way of doing is to use a hidden field in each form on the website. This hidden field is referred as CSRF token; it is nothing but a random value that alters with each HTTP request sent. As soon as it is inserted in the website forms, it gets saved in the user’s session as well. So, when the form is submitted by the users, the website checks whether it is the same as the one saved in the session. If it is same then, the request is legitimate.
21. Explain how you can enable CSRF (Cross Site Request Forgery) in CodeIgniter?
You can activate CSRF (Cross Site Request Forgery) protection in CodeIgniter by operating your application/config/config.php file and setting it to
[code] $config [ 'csrf_protection'] = TRUE; [/code]
If you avail the form helper, the form_open() function will insert a hidden csrf field in your forms automatically
22. What are CodeIgniter drivers?
These are special type of library that has a parent class and many child classes. These child classes have access to the parent class, but not to their siblings. Drivers are found in system/libraries folder.
23. How to initialize a driver in CodeIgniter?
To initialize a driver, write the following syntax,
[code] $this->load->driver('class_name'); [/code]