Zend Framework Interview Questions and Answers

What is zend framework?
Zend Framework is an open source, object oriented web application framework for PHP 5. Zend Framework is often called a ‘component library’, because it has many loosely coupled components that you can use more or less independently. But Zend Framework also provides an advanced Model-View-Controller (MVC) implementation that can be used to establish a basic structure for your Zend Framework applications.
What is advantages for Zend Framework ?
There are some advantages of using the Zend Framework:
It helps in making the web applications with ease and faster.
It has architecture with loosely coupled components and minimal inter dependencies
MVC Architecture or Model- View- Controller is pattern delimitates the database and business logic from the presentation layer and makes the code simple, clean and understandable.
Support for multiple database systems and vendors
It also has a flexible caching sub-system with support for many types of back-ends
Great Scope for customization
Meaningful & attractive URL database
has the feature to compose & send emails
AJAX is supported via JSON making the customer happy.
Search – Inclusion of a native PHP edition
The data formats & easy access to them your Web 2.0 applications need
Zend Framework now allows to consume & publish web services
High-quality, object-oriented PHP 5 class library giving attention to best practices.
Zend makes the code reusable, preventing repetition
The RAD(Rapid Application developement) extends great to the tooling support & command line
Supports the-use of multi language
How to disable layout from controller?

1
$this->_helper->layout()->disableLayout();

Disable Zend Layout from controller for Ajax call only

1
2
3
if($this->getRequest()->isXmlHttpRequest()){
$this->_helper->layout()->disableLayout();
}

How to protect your site from sql injection in zend when using select query?

1
2
3
4
5
$select = $this->select()
->from(array('u' => 'users'), array('id', 'username'))
->where('name like ?',"%php%")
->where('user_id=?','5')
->where('rating<=?',10);

How to get all POST data?

1
$this->getRequest()->getPost();

How to get all GET data?

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

How to get variable’s value from get?

1
$id= $this->getRequest()->getParam('id');

Create Model file in zend framework?

1
2
3
4
class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = "users";
protected $_primary = "id";
}

How to create object of Model?

1
$userObj = new Application_Model_Users();

Which Class extend the Zend Controller?

1
2
3
4
Zend_Controller_Action
For Example
class AjaxController extends Zend_Controller_Action {
}

Which Class extend the zend Model?
Zend_Db_Table_Abstract
For Example

1
class Application_Model_Users extends Zend_Db_Table_Abstract { }

Why should we use framework?
Framework is a structured system where we get following things
Rapid application development(RAD).
Source codes become more manageable.
Easy to extend features.
Where we set configuration in zend framework?
We set the config in application.ini which is located in application/configs/application.ini.
What is Front Controller?
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.
What is full form of CLA in Zend Framework?
Contributor License Agreement
Should I sign an individual CLA or a corporate CLA?
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.
How to include js from controller and view in Zend?
From within a view file: $this->headScript()->appendFile(‘filename.js’); From within a controller: $this->view->headScript()->appendFile(‘filename.js’); And then somewhere in your layout you need to echo out your headScript object: $this->headScript();
What are Naming Convention for PHP File?
1. There should not any PHP closing tag (?>)in controller & Model file.
2. Indentation should consist of 4 spaces. Tabs are not allowed.
3. The target line length is 80 characters, The maximum length of any line of PHP code is 120 characters.
4. Line termination follows the Unix text file convention. Lines must end with a single linefeed (LF) character. Linefeed characters are represented as ordinal 10, or hexadecimal 0x0A
What are Naming Convention for Classes, Interfaces, FileNames, Functions, Methods, Variables and constants?
http://framework.zend.com/manual/1.11/en/coding-standard.naming-conventions.html
What are coding style of Zend Framework?
http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html
How to use update statemnet in Zend Framework?

1
2
3
4
5
6
7
8
class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = 'users';
protected $_primary = 'id';
function updateData($updateData = array()) {
//please update dynamic data
$this->update(array('name' => 'arun', 'type' => 'user'), array('id=?' => 10));
}
}

How we can do multiple column ordering in Zend Framework?

1
2
3
4
5
6
7
8
9
10
 class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = 'users';
protected $_primary = 'id';
function users() {
$select = $this->select()
->setIntegrityCheck(false)
->from(array('u' => 'users'), array('name as t_name'))->order('first_name asc')->order('last_name des');
return $this->fetchAll($select);
}
}

Disable Zend Layout from controller for Ajax call only

1
2
3
if($this->getRequest()->isXmlHttpRequest()){
$this->_helper->layout()->disableLayout();
}

How to get variable’s value from get?

1
$id= $this->getRequest()->getParam('id');

Create Model file in zend framework?

1
2
3
4
class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = "users";
protected $_primary = "id";
}

How to create object of Model?

1
$userObj = new Application_Model_Users();

Which Class extend the Zend Controller?

1
2
3
4
Zend_Controller_Action
For Example
class AjaxController extends Zend_Controller_Action {
}

Which Class extend the zend Model?

1
Zend_Db_Table_Abstract

For Example

1
class Application_Model_Users extends Zend_Db_Table_Abstract { }

Why should we use framework?
Framework is a structured system where we get following things
Rapid application development(RAD).
Source codes become more manageable.
Easy to extend features.
Where we set configuration in zend framework?
We set the config in application.ini which is located in application/configs/application.ini.
What is Front Controller?
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.
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.
What is Zend auth?
It is used to authenticate user, for example like admin, general etc.
What Zend Acl?
Based on the zend authentication it allows the user to access certain actions.
What is application.ini file in Zend Framework?
Configuration can be done in application.ini file in Zend framework. This file in the path application/configs/application.ini.
Checking whether form posted or not in Zend framework?

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

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.
When do we need to disable layout?
At the time of calling AJAX to fetch we need to disable layout.

1
2
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

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.
Can we call a model in view?
Yes, you can call a model in view. Simple create the object and call the method.
How to include css from controller and view in zend ?
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();
How can you get a module name in bootstrap file ?

1
2
3
4
$router = new Zend_Controller_Router_Rewrite();
$request = new Zend_Controller_Request_Http();
$router->route($request);
$moduleName = $request->getModuleName();

Name some Important component in zend framework?
Gives the request & reponse methods by using its sub-classes.

1
2
$request = new Zend_Controller_Request_Http()
$response = new Zend_Controller_Response_Http()

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.

1
2
3
4
$auth = Zend_Auth::getInstance();
$results = $auth->authenticate($adapter);
if ($results->isValid()){
}

Zend_Session_Namespace
This is a simple proxy class to use API into the Zend_Session managed $_SESSION Superglobal.
How to call two different views from same action?

1
2
3
4
5
6
7
8
9
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’));

What is a Framework?
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
How to change the View render file from controller?

1
2
3
4
function listAction(){
//call another view file file
$this->render(“anotherViewFile”);
}

How to get variable’s value from get?

1
$id= $this-&gt;getRequest()-&gt;getParam(‘id’);

Create Model file in zend framework?

1
2
3
4
class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = “users”;
protected $_primary = “id”;
}

How to create object of Model?

1
$userObj = new Application_Model_Users();

Which Class extend the Zend Controller?

1
2
3
4
Zend_Controller_Action
For Example:
class AjaxController extends Zend_Controller_Action {
}

Which Class extend the zend Model?

1
2
3
Zend_Db_Table_Abstract
For Example :
class Application_Model_Users extends Zend_Db_Table_Abstract { }

Why should we use framework?
Framework is a structured system where we get following things
Rapid application development(RAD).
Source codes become more manageable.
Easy to extend features.
Where we set configuration in zend framework?
We set the config in application.ini which is located in application/configs/application.ini.
What is Front Controller?
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.
What is full form of CLA in Zend Framework?
Contributor License Agreement
Should I sign an individual CLA or a corporate CLA?
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.
How to include js from controller and view in Zend?
From within a view file: $this->headScript()->appendFile(‘filename.js’); From within a controller: $this->view->headScript()->appendFile(‘filename.js’); And then somewhere in your layout you need to echo out your headScript object: $this->headScript();
What are Naming Convention for PHP File?
1.There should not any PHP closing tag (?>)in controller & Model file.
2. Indentation should consist of 4 spaces. Tabs are not allowed.
3. The target line length is 80 characters, The maximum length of any line of PHP code is 120 characters.
4. Line termination follows the Unix text file convention. Lines must end with a single linefeed (LF) character. Linefeed characters are represented as ordinal 10, or hexadecimal 0x0A
What Zend Acl?
Based on the zend authentication it allows the user to access certain actions.
How to use update statemnet in Zend Framework?

1
2
3
4
5
6
7
8
9
class Application_Model_Users extends Zend_Db_Table_Abstract
{
protected $_name = ‘users’;
protected $_primary = ‘id’;
function updateData($updateData = array()) {
//please update dynamic data
$this->update(array(‘name’ => ‘arun’, ‘type’ => ‘user’), array(‘id=?’ => 10));
}
}

How we can do multiple column ordering in Zend Framework?

1
2
3
4
5
6
7
8
9
10
class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = ‘users’;
protected $_primary = ‘id’;
function users() {
$select = $this->select()
->setIntegrityCheck(false)
->from(array(‘u’ => ‘users’), array(‘name as t_name’))->order(‘first_name asc’)->order(‘last_name des’);
return $this->fetchAll($select);
}
}

.Why should we use framework?
Framework is a structured system
Source codes become more manageable
Easy to extend features
Rapid application development
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.
.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.
What is Bootstrapping?
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.
What is zend engine?
Zend Engine is used internally by PHP as a complier and runtime engine. PHP Scripts are loaded into memory and compiled into Zend opcodes.
What is zend engine in PHP?
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.
what is routing and how it’s work?
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.
What are Plugins in zend framework?
• 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
Zend_Cache provides a generic way to cache any data.
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.
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
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.
When do we need to disable layout?
At the time of calling AJAX to fetch we need to disable layout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);</codb>
<b>Where is the model in ZF’s MVC implementation?<b>
The model component can vary dramatically in responsibilities and data store from one MVC application to the next.
<b>How to call two different views from same action?</b>
<code>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’));

How to include css from controller and view in zend.
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();?>
How do you protect your site from sql injection in zend when using select query?
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 ( ” = ? “, );
What is MVC?
Model-View-Controller development pattern.
MVC is a software approach that separates application logic from presentation.
Features of MVC in Zend Framework?
Declare custom routing rulesNot limited to “controller/action/param” format
Optional Controller Plugins, Action Helpers, and View HelpersErrorHandler plugin handles exceptions, 404 errors, etc.FlashMessenger, Redirector, ViewRenderer helpersOutput common HTML elements in views
Extensible interfaces
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 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.
Why does the Zend Framework project have a CLA at all?
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.
Should I sign an individual CLA or a corporate CLA?
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.
Name some Important component in zend framework?
Gives the request & reponse methods by using its sub-classes.

1
2
$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()){
}
Zend_Session_Namespace
This is a simple proxy class to use API into the Zend_Session managed $_SESSION Superglobal.
ZF component library and framework?
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.
What is autoloader in Zend framework?
Auto loader is function that load all the object on start up.
What is the use of Bootstrap in zend framework?
Apart from index if we want to do any extra configuration regarding database and other things that is done within bootstrap.
What is the use of Bootstrap in Zend?
Apart from index if we want to do any extra configuration regarding database and other things that is done within bootstrap.
How to include js from controller and view in Zend?
In view File
$this->headScript()->appendFile(‘file.js’);
In Controller
$this->view->headScript()->appendFile(‘file.js’);
What is full form of CLA in Zend Framework?
Contributor License Agreement
Where we set configuration in zend framework?
Se configuration in application.ini which is located in application/configs/application.ini
What is Acl in Zend Framework?
Based on the zend authentication it allows the user to access certain actions.
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.
How to create object of Model in Zend?
$itemObj = new Application_Model_Items();
What is Zend auth?
It is used to authenticate user, for example like admin, general etc.
How to create Model file in zend framework?

1
2
3
4
 class Application_Model_Items extends Zend_Db_Table_Abstract {
    protected $_name = "items";
    protected $_primary = "id";      
}

How to get variable’s value from get?

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

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

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

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.
Can we call a model in view?
Yes, you can call a model in view. Simple create the object and call the method.
How to redirect to another page from controller?

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

How can you get a module name in bootstrap file ?

1
2
3
4
$router = new Zend_Controller_Router_Rewrite();
$request = new Zend_Controller_Request_Http();
$router->route($request);
$moduleName = $request->getModuleName();

What is the uses of Zend_Date
Date related processing can be done using this component.
What is the uses of Zend_File_Transfer
it provides extensive support for file uploads and downloads.
How to check post method in zend framework?

1
2
3
4
5
if($this->getRequest()->isPost()){
 // Yes post method
}else{
// Not post method
}

What is the uses of Uses of Zend_Db
It is used to doing database related purpose in our appication.
Disable Zend Layout from controller for Ajax call only?

1
2
3
4
// checking for ajax call
if($this->getRequest()->isXmlHttpRequest()){
    $this->_helper->layout()->disableLayout();
}

Leave a Reply

Your email address will not be published. Required fields are marked *