CodeIgniter Interview Questions and Answers
1.What is CodeIgniter ?
Answers : CodeIgniter is open source & powerful framework used for developing web applications on PHP. It is based on MVC(Model, View, Controller) pattern.
2. What are the features of CodeIgniter ?
Answer : 1. It is an open source framework and free to use.
2. It is extremely light weighted.
3. It is based on MVC(Model, View, Controller) pattern.
4.It has full featured database classes and support for several platforms.
5.Excellent documentation.
3. How you can add or load a model in CodeIgniter ?
Answer :
1 |
$this->load->model('Model_Name'); |
Answer : To connect database manually use following syntax :
1 |
$this>load->database(); |
Answer : View folder contains all the markup files like header,footer, sidebar etc. They can be reused by embedding them anywhere in the controller file. They can’t called directly, they have to be loaded in the controller file.
6. How can you load a view in CodeIgniter ?
Answer :
1 |
$this->load->view('Page_Name'); |
Answer : A Controller is the intermediate between models and view to process HTTP request and generates a web page. It is the center of every request on your web application.
8. What is the default controller in CodeIgniter ?
Answer : The file specified in default controller will be loaded by default .When no file name is mentioned in the URL. By default, it is welcome.php which is the first page to be seen after installing CodeIgniter.
9. What is the basic CodeIginter URL structure ?
Answer : Instead of using query-string approach, it uses a segment base approach.
It’s structure is as follows :
xyz.com/class/function/Id
Class represent controller class that need to be invoked.
Function is the method that is called.
Id is any additional segment that is passed to controllers.
10.How will you call a constructor in CodeIgniter ?
Answer :
1 |
parent::_construct(); |
Answer : CodeIgniter’s hooks feature provide a way to change the inner working of framework without hacking the core files. In other words, hooks allow you to execute a script with a particular path with in the CodeIgniter. Usually, it is defined in application/config/hooks.php file.
The hoks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file :
$config[‘enablehooks’]=TRUE;
12.Explain what helpers in CodeIgniter are and how you can load a helper file ?
Answer : 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 can load helper file using command
$this->load->helper(‘name’);
13. Explain routing in CodeIgniter ?
Answer : 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 specified controller and function.
14. Why is there a need to configure the URL routes ?
Answer : Changing the URL routes has some benfits like from SEO point of view, to make URL SEO friendly and get more user visits hide some URL element such as a function name, controller name, etc. from the users for security reasons provide different functionality to particular parts of a system.
15. List out different types of hook point in CodeIgniter ?
Answer : Different types of hook point in CodeIgniter includes
post_controller_constructor
pre_controller
post_system
pre_system
cache_override
display_override
post_controller
$hook[‘pre_controller’]=array(
‘class’=>’MyClass’,
‘function’=>’MyFunction’,
‘filename’=>’Myclass.php’,
‘filepath’=>’hooks’,
‘params’=>array(‘param1′,’param2′,’param3’)
);
16.Explain what is inhibitor in CodeIgniter ?
Answer : For CodeIgniter, inhibitor is an error handler class, using the native PHP functions like set_exception_hnadler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.
17. Explain how you can extend the class in CodeIgniter ?
Answer : 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
1 2 3 |
Class MY_Input extends CI_Input { } |
Answer : You can activate CSRF (Cross Site Request Forgery) protection in CodeIgniter by operating application/config/config.php file and setting it to $config[‘csrf_protection’]=TRUE; If the form helper, the from_open() function will insert a hidden csrf field in your forms automatically.
19. In which language CodeIgniter is written ?
Answer : PHP
20. How to access config variable in CodeIgniter ?
Answer :
1 |
$this->config->item('variable_name'); |
Answer :
1 |
$this->session->unsetuserdata('somename'); |
Answer :
1 |
$this->db->insertid(); |