Zend Framework Interview Questions & Answers

Posted On:January 29, 2019, Posted By: Latest Interview Questions, Views: 1441, Rating :

Best Zend Framework Interview Questions and Answers

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.

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

Interview Questions on Zend Framework

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

 

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

 

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

 

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

 

6. I want to use a SQL function or perform calculations in a statement I'm generating with Zend_Db_Select. How can I do this?

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'),

));

 

7. Is ZF a component library or a framework?

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.

 

8. What is autoloader?

Autoloader is function that load all the object on start up.

 

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

 

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

 

11. Zend auth?

It is used to authenticate user, for example like admin, general etc.

 

12. Zend Acl?

Based on the zend authentication it allows the user to access certain actions.

 

13. How do u set Module name, Controller name, and Action name in Zend framework?

a) $request->setModuleName(‘front’);

b) $request->setControllerName(‘address’);

c) $request->setActionName(‘addresslist’);

 

14. Configuration in Zend Framework, application.ini file?

Configuration can be done in application.ini file in Zend framework. This file in the path application/configs/application.ini.

 

15. Checking whether form posted or not in Zend framework?

$request = $this->getRequest();

$_GET = $request->getParams();

$_POST = $request->getPost();

 

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.

 

21. Name some important component in zend framework?

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.

 

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

 

23. 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’));

 

24. Can we call a model in view?

Yes, you can call a model in view. Simple create the object and call the method.

 

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

 

26. 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')

));

 

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

 

28. Custom function to Fetch last Insert ID in Zend Framework

 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();

 }