Zend Framework Interview Question Answers
Zend Framework Interview Question Answers
Extending the art & spirit of PHP, Zend Framework is based on simplicity, object-oriented best
practices, corporate friendly licensing, and a rigorously tested agile codebase. Zend Framework is
focused on building more secure, reliable, and modern Web 2.0 applications & web services, and
consuming widely available APIs from leading vendors like Google, Amazon, Yahoo!, Flickr, as well as API
providers and cataloguers like StrikeIron and ProgrammableWeb.
Which version of PHP does Zend Framework require? 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. See the requirements appendix for more information.
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.
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.
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. 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.
Is ZF a component library or a framework? 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.
Where's the model? 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.
How to use a SQL function or perform calculations in a statement generating with Zend_Db_Select ?
Actually, by default, if your expression includes parentheses, Zend_Db_Select will cast the statement
appropriately. However, if it does not, or you are having problems, you can use Zend_Db_Expr to
explicitly create the expression:
Zend_Auth is used for authenticating users with a variety of authentication methods, including
LDAP, OpenID, and HTTP. Authentication is the process of verifying that the provided credentials are
valid for the system. By authenticating to your system, your users can prove that they are who they say
they are. For more information on Zend Framework's authentication implementation, see the
Zend_Auth documentation.
Zend_Auth and Zend_Acl can be used together to build very sophisticated security systems: first
the user confirms their identity with Zend_Auth, then this identity is used to assign one or more
Zend_Acl roles to the user for authorization to use or modify resources in the system
How to use a SQL function or perform calculations in a statement generating with Zend_Db_Select?
How can I add extra HTML (such as a link) to my form element? This can easily be done using
decorators. For instance using the Description decorator. It is important to note though that you will
need to turn off escaping for the output of the decorator:
$element->setDecorators(array(
array('ViewHelper'),
array('Description', array('escape', false)),
array('Errors'),
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
));
Now, you can use the following to add extra HTML to the element:
$element->setDescription('<strong>This contains HTML that will actually be parsed by the browser, not
escaped</strong>');
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')
));
How can I detect if an optional file has been uploaded? 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 : latest release)
Use getFileInfo which will have an empty 'file' key and the flag 'isUploaded' set to false
Other Qns
Ques. What is a framework? Ans. In software development, a framework is a defined support structure
in which another software project can be organized and developed.
An abstract design
Set of common functionality
Developed for a particular domain
$request = $this->getRequest();
$_GET = $request->getParams();
$_POST = $request->getPost();
Ques . What is Bootstrapping? Ans. Many PHP applications funnel server requests into a single (or few)
PHP source file that sets up the environment and configuration for the application, manages sessions
and caching, and invokes the dispatcher for their MVC framework. They can do more, but their main job
is to take care of the consistent needs of every page of a web application.
In our Blueprint for PHP Applications, we will have a core bootstrapper that receives all dynamic
requests for an application and applies a template for application behavior that we can later extend. It
will allow us to later customize the functionality for each unique application.
Ques . What is zend engine? Ans. Zend Engine is used internally by PHP as a complier and runtime
engine. PHP Scripts are loaded into memory and compiled into Zend opcodes.
Ques . What is zend engine in PHP? Ans. Zend engine is like a virtual machine and is an open source, and
is known for its role in automating the web using PHP. Zend is named after its developers Zeev and
Aandi. Its reliability, performance and extensibility has a significant role in increasing the PHP’s
popularity. The Zend Engine II is the heart of PHP 5. It is an open source project and freely available
under BSD style license.
Ques . what is routing and how it's work? Ans. Zend_Controller_Router_Rewrite is the standard
framework router. Routing is the process of taking a URI endpoint (that part of the URI which comes
after the base URL) and decomposing it into parameters to determine which module, controller, and
action of that controller should receive the request. This values of the module, controller, action and
other parameters are packaged into a Zend_Controller_Request_Http object which is then processed by
Zend_Controller_Dispatcher_Standard. Routing occurs only once: when the request is initially received
and before the first controller is dispatched.
Creating Plugins:
• Extend Zend_Controller_Plugin_Abstract
• Extend one or more of the event methods
Ans. Caching in Zend Framework is operated by frontends while cache records are stored through
backend adapters (File, Sqlite,Memcache...) through a flexible system of IDs and tags. Using those, it is
easy to delete specific types of records afterwards (for example: "delete all cache records marked with a
given tag").
The core of the module (Zend_Cache_Core) is generic, flexible and configurable. Yet, for your specific
needs there are cache frontends that extend Zend_Cache_Core for convenience: Output, File, Function
and Class.
Ans. The basic difference between these objects is the ‘scope’ in which they are valid:
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 . When do we need to disable layout? Ans. At the time of calling AJAX to fetch we need to disable
layout.
• $this->_helper->layout()->disableLayout();
• $this->_helper->viewRenderer->setNoRender(true);
Example1:
Example2:
Now in your index.phtml you can have this statement to call other view
And then somewhere in your layout you need to echo out your headLink object: headLink();?>
Ques . How do you protect your site from sql injection in zend when using select query?
1. $this->getAdapter ()->quote ( );
2. $select->where ( ” = “, );
3. OR (If you are using the question mark after equal to sign)
4. $select->where ( ” = ? “, );
Ques . What is MVC?Ans.
Ques . Why can't Zend_Form render my File element without errors? Ans. 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:
1. $element->setDecorators(array(
2. array('ViewHelper'),
3. array('Errors')
4. ));
You should use a File decorator instead of the ViewHelper for the file element, like so:
1. $element->setDecorators(array(
2. array('File'),
3. array('Errors')
4. ));
Ques . How can I customize the appearance of forms generated by Zend_Form? Ans. You're probably
looking for decorators. All forms and form elements in Zend_Form use decorators to render their
output.
Ques . Why does the Zend Framework project have a CLA at all? Ans. 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 . Should I sign an individual CLA or a corporate CLA? Ans. 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.
Ques . What is Front Controller? Ans. It used Front Controller pattern. zend also use singleton pattern.
Other Qns
What is autoloader? Autoloader is function that load all the object on start up.
What is use of Zend front controller? Routing and dispatching is managed in the front controller. It
collects all the request from the server and handles it.
What is the use of Bootstrap? Apart from index if we want to do any extra configuration regarding
database and other things that is done within bootstrap.
Zend auth It is used to authenticate user, for example like admin, general etc.
Zend Acl Based on the zend authentication it allows the user to access certain actions.
How do set Module name, Controller name, and Action name in Zend framework?
1. $request->setModuleName(‘front’);
2. $request->setControllerName(‘address’);
3. $request->setActionName(‘addresslist’);
Fetch last inserted id, fetch all record and fetch a single record.
1. $this->_db->lastInsertId();
2. $this->_db->fetchAll($sql);
3. $this->_db->fetchRow($sql);
Difference between Zend_Registry and Zend_Session? The basic difference between these
objects is the ‘scope’ in which they are valid:
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.
When do we need to disable layout? At the time of calling AJAX to fetch we need to disable layout.
1. $this->_helper->layout()->disableLayout();
2. $this->_helper->viewRenderer->setNoRender(true);
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:
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.
Name some Important component in zend framework? Uses of Zend_Controller. Gives the
request & reponse methods by using its sub-classes.
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 application.
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.
Can we call a model in view? Yes, you can call a model in view. Simple create the object and call the
method.
Can we rename the application folder ?yes you can rename the application folder
Can we move the index.php file outside the public folder? yes you can move index.php file outside
And then somewhere in your layout you need to echo out your headScript object:
<?=$this->headScript();?>
And then somewhere in your layout you need to echo out your headLink object:
<?=$this->headLink();?>