CodeIgniter Interview Questions and Answers
CodeIgniter Interview Questions and Answers
Codeigniter is the most popular open-source framework for web application. It can be used to develop any kind of web project from a small website to large scale applications. It is loosely based on the popular model–view–controller (MVC) development pattern, and it is easy to use compare to other PHP frameworks. The first public version of CodeIgniter was released by EllisLab on February 28, 2006.
Question 1: What is Codeigniter?
Codeigniter (CI) is the most popular open-source framework for web application. It can be used to develop any kind of web project from small websites to large scale applications. It is loosely based on the popular model–view–controller (MVC) development pattern, and it is easy to use compare to other PHP frameworks.The first public version of CodeIgniter was released by EllisLab on February 28, 2006.
Question 2: What are the features of Codeigniter?
- Codeigniter is free to use,its an open source framework.
- Model View Controller Based System.
- Extremely Light Weight.
- Full Featured database classes with support for several platforms.
- CodeIgniter is Extensible.The system can be easily extended through the use of your own libraries, helpers, or through class extensions or system hooks.
- Full Featured database classes with support for several platforms,Security and XSS Filtering,Error Logging.
Question 3: Explain Codeigniter File Structure?
following are the folder structure :
application
- cache
- Config
- Controllers
- core
- errors
- helpers
- hooks
- language
- libraries
- logs
- models
- third-party
- views
system
- core
- database
- fonts
- helpers
- language
- libraries
assets
- css
- images
- js
Question 4: Explain what are hooks in CodeIgniter?
Codeigniter`s hooks feature provides a way to change the inner working of the framework without hacking the core files. In other word, hooks allow you to execute a script with a particular path within the Codeigniter. Usually, it is defined in application/config/hooks.php file.
1 2 3 4 5 6 7 8 9 10 |
<?php // hook $hook['pre_controller'] = array( 'class' => 'MyClass', 'function' => 'Myfunction', 'filename' => 'Myclass.php', 'filepath' => 'hooks', 'params' => array('param1', 'param2', 'param3') ); ?> |
Question 5: How to load model in CodeIgniter?
Within your controller functions, models will typically be loaded; you will use the function
1 2 3 4 |
<?php // syntax $this->load->model (‘Model_Name’); ?> |
Question 6: How to connect multiple databases in CodeIgniter?
To CodeIgniter connect multiple database simultaneously, use following Syntax:
1 2 3 4 |
<?php $DB1 = $this->load->database('group_one', TRUE); $DB2 = $this->load->database('group_two', TRUE); ?> |
Question 7: Explain what helpers in CodeIgniter are and how you can load a helper file?
In CodeIgniter, helpers are group of function in a particular category that assist you to perform specific functions. In CodeIgniter, you will find many helpers like URL helpers- helping in creating links, Text helpers- perform various text formatting routines, Cookies- helpers set and read cookies. You can load helper file by using command:
1 2 3 4 |
<?php // load helper $this->load->helper ('helper-name'); ?> |
Question 8: How can you load multiple helper files?
To load multiple helper files like:
1 2 3 4 5 6 |
<?php // syntax $this->load->helper( array('helpername1', 'helpername2', 'helpername3') ); ?> |
Question 9: Explain CodeIgniter library. How will you load it?
It is an essential part of CodeIgniter as it increases the developing speed of an application. To load library use following Syntax:
1 2 3 4 |
<?php // load syntax $this->load->library('lib_class_name'); ?> |
Question 10: Explain routing in Codeigniter?
In CodeIgniter, the way PHP files served is different rather than accessing it directly from the browser. This process is called routing. Routing in CodeIgniter gives you the freedom to customize the default URL pattern to use our own URL pattern according to the requirement. So, whenever there is a request made and matches our URL pattern it will automatically direct to the specified controller and function.
Question 11: How to connect models to a database manually?
Connect database manually:
1 2 3 4 |
<?php // Syntax Connect database manually $this->load->database(); ?> |
Question 12: What is inhibitor in CodeIgniter?
Inhibitor is an error handler class that uses native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.
Question 13: What are CodeIgniter security methods?
In CodeIgniter, The Security Class contains methods that help you create a secure application, processing input data for security.
- XSS Filtering
- Cross-site request forgery (CSRF)
Question 14: What are the security parameters for XSS in CodeIgniter?
In CodeIgniter, XSS stands for cross-site scripting. There are some cross-site scripting hack prevention filters in CodeIgniter.
1 2 3 4 |
<?php // syntax $data = $this->security->xss_clean($data); ?> |
Question 15: How can you enable CSRF in CodeIgniter?
To enable CRSF in Codeigniter all you need to do is:
1 2 3 4 |
<?php // syntax $config ['csrf_protection'] = TRUE; ?> |
Set the option to “TRUE” in the application/config/config.php