Top Interview Questions and Answers

Top Interview Questions and Answers
Interview Sortout

Browsing "Older Posts"

Top 10 Codeigniter Interview Questions and Answers for Experienced

By Dhananjay yadav → May 31, 2018


1- What is hook?
CodeIgniter’s Hooks feature modify the core functionalitis of the framework without changing the core files. For example, If you want to run a script right before your controllers get loaded, or right after or at any other location, you can use Hook.

2- How many types of hooks are there in Code Igniter?
There are 7 availabe hook points:

pre_system :
Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.

pre_controller :
Called prior to controllers being called. All base classes, routing, and security checks have been done.

post_controller_constructor:
Called after controller is instantiated, but prior to any method calls happening.

post_controller:
Called after the controller is executed.

display_override:
Overrides the _display() method, used to send the finalized page to the web browser at the end of system execution. This permits you to use your own display methodology. Note that you will need to reference the CI superobject with $this->CI->get_instance() and then the finalized data will be available by calling $this->CI->output->get_output().



cache_override:

Enables you to call your own method instead of the _display_cache() method in the Output Library. This permits you to use your own cache display mechanism.

post_system:
Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.

Creating a hook :
$my_hook=array(
'class' => 'YourClassname',
'function' => 'your_function_name',
'filename' => 'your_filename.php',
'params' => array('p1', 'p2')
'filepath' => 'hooks', );
$hook['pre_controller'] = $my_hook;

3- Can we use multiple call to same hook?
Yes , we can use multiple call to same hook. Then We have to use multidimentional array:
$hook['pre_controller'][]= $hook_one;
$hook['pre_controller'][]= $hook_two;

4- What are the benifites of using hook in an application?
-We can modify core functionalitis without touching the core files.
-We can generate derired output without changing the view files.
-we can make a hook for recurring calls , like including footer and header in each function, without calling them in each controller function.
-we can create a script to minify the code before excecution take place.
-We can easily implement security checks, privacy, session, cache using hooks and can seperate these implementation from the main functionalitis.

5- WHat is HMVC?
HMVC is a Modular version of MVC. In this system we can implement modules for particular purpose. We may have put out controller , views and model in different modules. All these modules will be available in modules folder in application. HMVC stands for Hierarchical Model View Controller.



6- What is a module?

A module is a part of application and a full featured block which is implemented on HMVC pattern. A module contains its own Model, View and Controller. Although these resources can be shared with other modules.



7- What is difference between Library and Helper?


A CodeIgniter helper is a set of related global functions, you can call them any where in application. Once you load the helper file you can directly call the function. Basically the helper is procedural.

But a Library is a class, which you need to make an instance of the class. Once the library is loaded, we need to use $this operator to call the Library function. This is Object Oriented.




8- What is Routes in Code Igniter Framework?

Routing is the communication between URI and Controller. Routing decides the controller calls and parameters in code igniter. We can overwrite the routing rules in routes.php file.


9- How to use or enable libraries CodeIgniter?
We can initialize the library in controllers as given below:
$this->load->library('my_library_class');

10- Why CodeIgniter is a loosely coupled mvc framework?
CodeIgniter is called a loosely coupled mvc because, it provides unlimited flexibility to developers. It allows us to write and execute our custom codes, library, helpers. We can use call model and controllers functions in views and also can write custom code on views. It works like a core php when some one is going to manipulate it and on the other side it provide a modular structure to our application, XSS and CSRF functionalitis. It provides us lots of inbuilt library and also compatible with many more custome libraries. It never restricts us to write and execute any code.