Dear Readers, Welcome to Zend Framework Interview Questions and Answers have been designed specially to get you acquainted with the nature of questions you may encounter during your Job interview for the subject of Zend Framework. These Zend Framework Questions are very important for campus placement test and job interviews. As per my experience good interviewers hardly plan to ask any particular questions during your Job interview and these model questions are asked in the online technical test and interview of many IT companies.
Zend Framework requires PHP 5.2.4 and up. Some Zend Framework components may work with earlier versions of PHP, but these components are tested and supported only on 5.2.4 and up.
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.
Another consideration was support of the platform ZF would be running on. The PHP community officially discontinued support for PHP 4 as of 2008-01-01, and no critical security updates will be published for PHP 4 after 2008-08-08.
These factors, among others, convinced us that PHP 5 was the best platform for Zend Framework and applications built on ZF.
The model component can vary dramatically in responsibilities and data store from one MVC application to the next. The ZF community has not defined a model interface, class, or other formalism simply because we wanted to avoid introducing limitations without significant added value.
Simple answer: both. Zend Framework provides all the components required for most web applications in a single distribution. But Zend Framework components are also loosely coupled, making it easy to use just a few components in a web application- even alongside other frameworks! Using this use-at-will architecture, we are implementing features commonly found in more monolithic frameworks. In fact, we are currently working on a tooling component for the 1.8 release that will make it simpler to build applications using ZF components, yet will not sacrifice the use-at-will nature of existing ZF components. It's a testament to the use-at-will architecture of Zend Framework that the tooling component itself can be used standalone.
Unlike the view and the controller components, the model component can vary dramatically in responsibilities and data storage from one MVC application to the next. It should represent what your application does in the abstract. The Zend Framework community has not defined a model interface, class, or other formalism because we haven't identified enough added value to justify limitations on what constitutes a model.
Actually, by default, if your expression includes parentheses, Zend_Db_Select will cast the statement appopriately. However, if it does not, or you are having problems, you can useZend_Db_Expr to explicitly create the expression:
* Build the SQL:
* SELECT p."product_id", p.cost * 1.08 AS cost_plus_tax
* FROM "products" AS p
*/
$select = $db->select()
->from(array('p' => 'products'),
array(
'product_id',
'cost_plus_tax' => new Zend_Db_Expr('p.cost * 1.08'),
));
ZF is both. Zend Framework provides all the components required for most web applications in a single distribution. But Zend Framework components are also loosely coupled, making it easy to use just a few components in a web application- even alongside other frameworks! Using this use-at-will architecture, we are implementing features commonly found in more monolithic frameworks. In fact, we are currently working on a tooling component for the 1.8 release that will make it simpler to build applications using ZF components, yet will not sacrifice the use-at-will nature of existing ZF components. It’s a testament to the use-at-will architecture of Zend Framework that the tooling component itself can be used standalone.
Autoloader is function that load all the object on start up.
Routing and dispatching is managed in the front controller. It collects all the request from the server and handles it.
Apart from index if we want to do any extra configuration regarding database and other things that is done within bootstrap.
It is used to authenticate user, for example like admin, general etc.
Based on the zend authentication it allows the user to access certain actions.
a) $request->setModuleName(‘front’);
b) $request->setControllerName(‘address’);
c) $request->setActionName(‘addresslist’);
Configuration can be done in application.ini file in Zend framework. This file in the path application/configs/application.ini.
$request = $this->getRequest();
$_GET = $request->getParams();
$_POST = $request->getPost();
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.
$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
$this->_db->fetchRow($sql);
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.
At the time of calling AJAX to fetch we need to disable layout.
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
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.
Uses of Zend_Controller
Gives the request & reponse methods by using its sub-classes.
$request = new Zend_Controller_Request_Http()
$response = new Zend_Controller_Response_Http()
Uses of Zend_Date
Date related processing can be done using this component.
Uses of Zend_File_Transfer
it provides extensive support for file uploads and downloads.
Uses of Zend_Db
It is used to doing database related purpose in our appication.
Uses of Zend_Paginator
Doing the pagination in our application.
Uses of Zend_Auth
It is used to authenticate a user.
$auth = Zend_Auth::getInstance();
$results = $auth->authenticate($adapter);
if ($results->isValid()){
/* user successfully authenticate into login process */
}
Zend_Session_Namespace
This is a simple proxy class to use API into the Zend_Session managed $_SESSION Superglobal.
The model component can vary dramatically in responsibilities and data store from one MVC application to the next.
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’));
Yes, you can call a model in view. Simple create the object and call the method.
You're probably looking for decorators. All forms and form elements in Zend_Form use decorators to render their output.
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')
));
The receive() method will return true for file elements that are not required. The reason is that you said "the file can be omitted, and that's ok for me". The receive() method will return false only in the event of a failure.
Still there are several ways to detect if a file has been uploaded or not:
Use isUploaded which returns a boolean
Use getFileName which returns null in this case (note that you must use the latest release for this behaviour)
Use getFileInfo which will have an empty 'file' key and the flag 'isUploaded' set to false
public function insertData($tableName,$colName) {
$this->_name = $tableName;
$sql = "INSERT INTO $tableName SET $colName";
$this->_db = $this->getAdapter();
$this->_db->query($sql);
return $this->_db->lastInsertId();
}