Thursday 5 February 2015

Zend Framework: Zend Interview questions and answers (Part4)

Below are some important Zend Framework interview questions which are asked in most MNC company interviews for beginners or professionals.
16. Does Zend Framework support PHP 4?
No. Zend Framework was built to use all of the sophisticated object oriented features of PHP 5 and take advantage of significant performance and security enhancements.

17. Fetch last inserted id, fetch all record and fetch a single record.
$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
$this->_db->fetchRow($sql);

18. 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
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.
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.


19. 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);

20. Filters in Zend Framework with Examples?
The Zend_Filter component provides a set of commonly needed data filters. It also provides a simple filter chaining mechanism by which multiple filters may be applied to a single datum in a user-defined order.
Example:
// Add an email element
$this->addElement(‘text’, ‘email’, array(
‘label’ => ‘Your email address:’,
‘required’ => true,
‘filters’ => array(‘StringTrim’),
‘validators’ => array(
‘EmailAddress’,
)
));
Other Filters:
Alnum – Zend_Filter_Alnum is a filter which returns only alphabetic characters and digits. All other characters are supressed.
Alpha – Zend_Filter_Alpha is a filter which returns the string $value, removing all but alphabetic characters. This filter includes an option to also allow white space characters.
More Questions & Answers :-
Part1  Part2  Part3  Part4  Part5

No comments:

Post a Comment