Here we have mentioned most frequently asked Zend Framework Interview Questions and Answers specially for freshers and experienced.


 

1. What does autoloader in Zend Framework?

Ans:

The Zend Framework has default Zend_Loader_Autoloader that’s called autoloader. The autoloader end the need to manually include the file. Whenever any class or interface called, the autoloader is called automatically to load all the objects.

2. What is Zend Controller Front in Zend Framework?

Ans:

In Zend framework, the Zend_Controller_Front implements front controller pattern used in Model-View-Controller of a applications. Its main purpose to manage the request, route the incoming request, and then dispatch actions.

3. What is the purpose of bootstrap in Zend framework??

Ans:

In Zend framework, the bootstrapping is the process to load the application. All the resources require to an application to process the request to the application is bootstrapped/loaded/initialized before the request is completed.

4. What is Zend\Authentication?

Ans:

The Zend\Authentication is the Zend component that related to authentication. It is used to determining entity based on certain set of credentials.

5. What is Authorization in Zend Framework?

Ans:

Unlike Authentication, the Zend Authorization is the process of deciding to allow access to entity or performing certain operations.

6. What Zend Permission Acl?

Ans:

The Zend\Permissions\Acl component is used in Zend application for access control to certain protected objects.

7. What is application.ini file in Zend Framework?

Ans:

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

8. Checking Form Post request in Zend Framework?

Ans:

We will check Form post request in Zend framework using below code:

if ($this->getRequest()->isPost()) {
echo "This is post request";
} else {
echo "This is not a post request";
}

9. How to include CSS in Zend framework?

Ans:

You can call below code in your .phtml with your CSS filename to include your CSS.
$this->headLink()->appendStylesheet(‘filename.css’);

10. Major component name of Zend framework?

Ans:

Here are some major Zend framework components name:
Zend_Auth
Zend_Acl
Zend_Config
Zend_Controller
Zend_Db
Zend_Form
Zend_Layout
Zend_Validate



 

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

12. Why should we use framework?

Ans:

Framework is a structured system
=> Source codes become more manageable
=> Easy to extend features
=> Rapid application development

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

Ans:

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

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

Ans:

if($this->getRequest()->isPost()){ echo “Form posted”; }

15. Does Zend Framework support PHP 4?

Ans:

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.

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

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

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

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

Zend_Controller_Router_Rewrite is designed to allow for mod_rewrite-like functionality using pure PHP structures. It is very loosely based on Ruby on Rails routing and does not require any prior knowledge of webserver URL rewriting. It is designed to work with a single Apache mod_rewrite rule.

20. What are Plugins in zend framework?

Ans:

• Triggered by front controller events
• Events bookend each major process of the front controller
• Allow automating actions that apply globally
Creating Plugins:
• Extend Zend_Controller_Plugin_Abstract
• Extend one or more of the event methods




 

21. Zend_Cache provides a generic way to cache any data.

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.

22. Difference between Zend_Registry and Zend_Session?

Ans:

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.

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

24. Where is the model in ZF’s MVC implementation?

Ans:

The model component can vary dramatically in responsibilities and data store from one MVC application to the next.

25. How to call two different views from same action?

Ans:

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

26. How to include css from controller and view in zend.

Ans:

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:
headLink();?>

27. How do you protect your site from sql injection in zend when using select query?

Ans:

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 ( ” = ? “, );

28. What is MVC?

Ans:

=> Model-View-Controller development pattern.
=> MVC is a software approach that separates application logic from presentation.

29. Features of MVC in Zend Framework?

Ans:

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

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

$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')
));

 

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

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

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

34. What is Front Controller?

Ans:

It used Front Controller pattern. zend also use singleton pattern.
=> routeStartup: This function is called before Zend_Controller_Front calls on the router to evaluate the request.
=> routeShutdown: This function is called after the router finishes routing the request.
=> dispatchLoopStartup: This is called before Zend_Controller_Front enters its dispatch loop.
=> preDispatch: called before an action is dispatched by the dispatcher.
=> postDispatch: is called after an action is dispatched by the dispatcher

35. Does Zend Framework support PHP 7?

Ans:

The current Zend framework 3 is fully supporting PHP 7 version.

36. How to disable layout in Zend framework?

Ans:

We need to disable layout when we make a AJAX request to fetch data. We will use below code to disable layout.
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

37. What is Zend Framework 2 ?

Ans:

zend Framework 2 is open source php framework

38. How to check post method in zend framework?

Ans:

if($this->getRequest()->isPost()){
// Yes post method
}else{
// Not post method
}

39. How to change the View render file from controller?

Ans:

function listAction(){
$this->render("anotherViewFile");
}

40. What is the uses of Uses of Zend_Db

Ans:

It is used to doing database related purpose in our appication.



 

41. How to render ZF2 view within JSON response?

Ans:

public function indexAction(){ if (!$this->getRequest()->isXmlHttpRequest()) { return array(); } $htmlViewPart = new ViewModel(); $htmlViewPart->setTerminal(true).

42. How to access route, post, get etc. parameters in Zend Framework 2?

Ans:

Get a single value:$this->params()->fromPost(‘paramname’); // From POST$this->params()->fromQuery(‘paramname’); // From GET$this->params()->fromRoute(‘paramname’); // From

43. How to set up 2 navigations in zend framework 2?

Ans:

There are four simple steps to make this happen.STEP ONEPut the navigation configuration in your module configuration first. Just as you have a default navigation, you can create a second one.

44. How to add custom view helpers to Zend Framework 2

Ans:

add view helpers to module.config.php under view_helpers like this’view_manager’ => array( ‘template_path_stack’ => array( ‘ModuleName’ => __DIR__ . ‘/../view’,

46. explain Form Element Decorators in zend framework2?

Ans:

use partials. build a few exceptions for eg CSRF and Submit.View:echo $this->partial(‘partial/form-partial’, array(‘form’ => $this->form,’url’ => $this->url

46. Which version of PHP does Zend Framework require?

Ans:

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.

47. What is the uses of Zend_File_Transfer

Ans:

it provides extensive support for file uploads and downloads.

48. Is ZF a component library or a framework?

Ans:

Zend Framework provides all the components required for most web applications in a single distri bution. But Zend Framework components are also loosely coupled, making it easy to use just a few.

49. How to use a SQL function or perform calculations in a statement generating with Zend_Db_Select?

Ans:

Actually, by default, if your expression includes parentheses, Zend_Db_Select will cast the statem ent appropriately . 

50. What is the difference between Zend_Auth and Zend_Acl?

Ans:

Zend_Auth is used for authenticating users with a variety of authentication methods, in cluding LDAP, OpenID, and HTTP . Authentication is the process of verifying that the provided credentials.




 

51. How can customize the appearance o f forms generated by Zend_Form?

Ans:

Decorators. All forms and form elements in Zend_Form use decorators to render

52. How can I add extra HTML (such as a link) to my form element?

Ans:

This can easily be done using decorators. For instance using the Descripti on decorator. It is important to note though that you will need to turn off escaping for the output

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

54. How can I detect if an optional file has been uploaded?

Ans:

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.

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

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

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

58. What are Plugins in zend framework?

Ans:

• Triggered by front controller events

• Events bookend eac h major process of the front controller

• Allow automating actions that apply globally Creating.

59. Zend_Cache provides a generic way to cache any data.?

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.

60. Features of MVC in Zend Framework?

Ans:

Declare custom routing rules o Not limited to “controller/action/param” format Optional Controller Plugins, Action Helpers, and View Helpers o ErrorHandler plugin.


 

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

62. Where we set configuration in zend framework?

Ans:

We set the config in application.ini which is located in application/configs/application.ini.

63. Which Class extend the Zend Controller? Zend_Controller_Action

Ans:

class AjaxController extends Zend_Controller_Action.

64. What is the uses of Zend_Date

Ans:

Date related processing can be done using this component.

65. How can you get a module name in bootstrap file ?

Ans:

$router = new Zend_Controller_Router_Rewrite();
$request = new Zend_Controller_Request_Http();
$router->route($request);
$moduleName = $request->getModuleName();

66. How to get all GET data?

Ans:

$this->getRequest()->getParams();

67. How we can do multiple column ordering in Zend Framework?

Ans:

class Application_Model_Users extends Zend_Db_Table_Abstract { protected $_name = ‘users’; protected $_primary

68. What is autoloader?

Ans:

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

69. How you can set Module name, Controller name, and Action name in Zend framework?

Ans:

$request->setModuleName(‘front’); $request->setControllerName(‘address’); $request->setActionName(‘addresslist’);

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

Ans:

$request = $this->getRequest(); $getData = $request->getParams(); $postData = $request->getPost(); $isPost = $request->isPost();



 

71. how to Fetch last inserted id, fetch all record,find and fetch a single record.

Ans:

$this->_db->lastInsertId(); $this->_db->fetchAll($sql); $this->_db->find($id); $this->_db->fetchRow($sql);

72. How to add extra HTML (i.e link) in Zend_Form?

Ans:

use Desciption decorator with (escape =false in second parameter).

73. What is zend helpers?

Ans:

It can be divided in two parts, a) Action Helper: the helper is created for controller b) View Helper: the helper is created for view files (.phtml).

74. What do you know about zend layout.

Ans:

It work as a site template and have following features.
Automatic selection and rendering layout.

75. What is Inflection?

Ans:

It is class in zend used to modify the string like convert to lowercase, change to url by removing special chars and convert underscore to hyphen.

76. What is Zend_filter?

Ans:

Zend_filter is used to filter the data as remove the tags, trailing the spaces, remove all except digits.

77. What is the use of Bootstrap in Zend?

Ans:

Apart from index if we want to do any extra configuration regarding database and other things that is done within bootstrap.

78. How to include js from controller and view in Zend?

Ans:

In view File
$this->headScript()->appendFile(‘file.js’);
In Controller
$this->view->headScript()->appendFile(‘file.js’);

79. What is full form of CLA in Zend Framework?

Ans:

Contributor License Agreement

80. Where we set configuration in zend framework?

Ans:

Se configuration in application.ini which is located in application/configs/application.ini




 

81. What is Acl in Zend Framework?

Ans:

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

82. What is use of Zend front controller?

Ans:

Routing and dispatching is managed in the front controller. It collects all the request from the server and handles it.

83. How to create object of Model in Zend?

Ans:

$itemObj = new Application_Model_Items();

84. What is Zend auth?

Ans:

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

85. How to create Model file in zend framework?

Ans:

class Application_Model_Items extends Zend_Db_Table_Abstract {
protected $_name = "items";
protected $_primary = "id";
}

86. How to get variable’s value from get?

Ans:

$name= $this->getRequest()->getParam('name');

87. How to Check whether form posted or not in Zend framework?

Ans:

$request = $this->getRequest();
$_POST = $request->getPost();
$_GET = $request->getParams();

88. Where is the model in ZF’s MVC implementation?

Ans:

The model component can vary dramatically in responsibilities and data store from one MVC application to the next.

89. Can we call a model in view?

Ans:

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

90. How to redirect to another page from controller?

Ans:

$this->_redirect('/users/login');