Zend Framework Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. Difference between Zend_Registry and Zend_Session?
The basic difference between these objects is the ‘scope’ in which they are valid:
a) Zend_Registry : request scope
b) Zend_Session : session scope
a) Zend_Registry is used to store objects/values for the current request. In short, anything that you commit to Registry in index.php can be accessed from other controllers/actions (because EVERY request is first routed to the index.php bootstrapper via the .htaccess file). Config parameters and db parameters are generally prepped for global use using the Zend_Registry object.
b) Zend_Session actually uses PHP sessions. Data stored using Zend_Session can be accessed in different/all pages. So, if you want to create a variable named ‘UserRole’ in the /auth/login script and want it to be accessible in /auth/redirect, you would use Zend_Session.
Ques 2. When do we need to disable layout?
At the time of calling AJAX to fetch we need to disable layout.
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
Ques 3. Where is the model in ZF’s MVC implementation?
The model component can vary dramatically in responsibilities and data store from one MVC application to the next.
Ques 4. How to call two different views from same action?
Example1:
Public function indexAction() {
If(condition)
$this->render(‘yourview.phtml’);
Else
Index.phtml;
Example2:
Public function indexAction() {
}
Now in your index.phtml you can have this statement to call other view
$this->action(‘action name’,’controller name’,’module name’,array(‘parameter name’=>’parameter value’));
Ques 5. How to include css from controller and view in zend.
From within a view file: $this->headLink()->appendStylesheet(‘filename.css’);
From within a controller: $this->view->headLink()->appendStylesheet(‘filename.css’);
And then somewhere in your layout you need to echo out your headLink object:
=$this->headLink();?>
Ques 6. How do you protect your site from sql injection in zend when using select query?
You have to quote the strings,
$this->getAdapter ()->quote (
$select->where ( ”
OR (If you are using the question mark after equal to sign)
$select->where ( ”
Ques 7. Features of MVC in Zend Framework?
=> Declare custom routing rules
Not limited to “controller/action/param” format
=> Optional Controller Plugins, Action Helpers, and View Helpers
ErrorHandler plugin handles exceptions, 404 errors, etc.
FlashMessenger, Redirector, ViewRenderer helpers
Output common HTML elements in views
=> Extensible interfaces
Write your own plugins and helpers
Ques 8. Why can't Zend_Form render my File element without errors?
The file element needs a special file decorator, which is added by default. When you set your own decorators for file elements, you delete the default decorators.
For example:
$element->setDecorators(array(
array('ViewHelper'),
array('Errors')
));
You should use a File decorator instead of the ViewHelper for the file element, like so:
$element->setDecorators(array(
array('File'),
array('Errors')
));
Ques 9. How can I customize the appearance of forms generated by Zend_Form?
You're probably looking for decorators. All forms and form elements in Zend_Form use decorators to render their output.
Ques 10. Why does the Zend Framework project have a CLA at all?
The CLA protects all users including individuals, small and medium businesses, and large corporations. By having a CLA in place, we mitigate the risk that companies who claim intellectual property infringement may demand royalties or fees from users of Zend Framework, whether individuals or companies. This is especially important for companies basing their business or products on Zend Framework. The Zend Framework CLA helps to ensure that code and other IP in Zend Framework remains free.
Ques 11. Should I sign an individual CLA or a corporate CLA?
If you are contributing code as an individual- and not as part of your job at a company- you should sign the individual CLA. If you are contributing code as part of your responsibilities as an employee at a company, you should submit a corporate CLA with the names of all co-workers that you foresee contributing to the project.
Most helpful rated by users:
- What is a framework?
- Why should we use framework?
- Configuration in Zend Framework, application.ini file?
- Checking whether form posted or not in Zend framework?
- Does Zend Framework support PHP 4?