Zend Interview Questions and Answers
Zend Interview Questions and Answers
1. Is Zend Framework a component library or a framework?
Routing and dispatching is managed in the front controller. It collects all the request from the server and handles it.
4. 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.
5.How you can set Module name, Controller name, and Action name in Zend framework?
$request->setModuleName(‘front’);
$request->setControllerName(‘address’);
$request->setActionName(‘addresslist’);
6.How to configure zend framework application?
Configuration can be done in application.ini file in Zend framework. This file in the path application/configs/application.ini.
7. Checking whether form posted or not in Zend framework?
$request = $this->getRequest();
$getData = $request->getParams();
$postData = $request->getPost();
$isPost = $request->isPost();
8.How to fetch last inserted id, fetch all record,find and fetch a single record.
$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
$this->_db->find($id);
$this->_db->fetchRow($sql);
9.Difference between Zend_Registry and Zend_Session?
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.
10. When do we need to disable layout?
OR (If you are using the question mark after equal to sign)
$select->where ( ” <field name> = ? “, <variable name> );
18. How to Create Form & Form Elements in zend framework?
//create a form object
$form = new Zend_Form
$form->setAction('/resource/process')->setMethod('post');
$form->setAttrib('id', 'login');
//Zend Form support Following form elements
button,
checkbox (one/many),
hidden,
image,
password,
radio,
reset,
select (single select/many select),
submit,
text,
textarea
19. What is Zend_Form?
It uses to create a form in zend framework. In this each input/select/radio/checkbox known as element.
Following are the zend form features.
20. List of All Zend Framework Components
Zend_ACL
Zend_Acl provides lightweight and flexible access control list (ACL) functionality and privileges management. In general, an application may utilize such functionality to control access to certain protected objects by other requesting objects.
Resource
creating a Resource is very simple. Zend_Acl provides Zend_Acl_Resource_Interfaceto facilitate developers' creating Resources. A class need only implement this interface, which consists of a single method, getResourceId();
Role
Zend_Acl providesZend_Acl_Role_Interface to facilitate developers' creating Roles. A class need only implement this interface, which consists of a single method, getRoleId(), in order for Zend_Acl to consider the object to be a Role. In Zend_Acl, a Role may inherit from one or more Roles. This is to support inheritance of rules among Role.
Example of ACL
<?php
?>
// Guest may only view content of all controller, Here 'view' can be an array having all the function which guest may access. null can be a string or an array, Here Null means all controller
$acl->allow($roleGuest, null, 'view');
// Here no controller or action is given, it means Administrator is allowed all privileges $acl->allow('administrator');
// Remove the denial of revising latest news to staff $acl->removeDeny('staff', 'latest', 'revise');
Assertions
Sometimes a rule for allowing or denying a Role access to a Resource should not be absolute but dependent upon various criteria. For example, suppose that certain access should be allowed, but only between the hours of 8:00am and 5:00pm. Another example would be denying access because a request comes from an IP address that has been flagged as a source of abuse.
<?php
Singleton Pattern: It is a design pattern that restricts the instantiation of a class to one object.
Example:
example
$db = Zend_Db::factory( ...options... );
23 .What is the difference between Zend_Auth and Zend_Acl?
- Zend_Auth provides the authentication protocol for the users using many methods whereas; Zend_Acl is used for authorization purpose. - Zend_Auth uses the methods like LDAP, OpenID and HTTP to provide the authentication, whereas Zend_Acl uses Access Control List for authorization. - Zend_Auth provide the authentication in the form of verifying and providing the credentials for the user’s system, whereas Zend_Acl uses list of roles that is being implemented only those who are authorized to it. - Zend_Auth provides an environment to the system through which user who is authenticated for use, whereas Zend_Acl performs some operations on the specific resources that need to be written on the system. - Zend_Auth supports the authentication platforms features, whereas Zend_Acl supports the advanced definitions with features of multiple inheritance and other similar features.
24 Write a program that performs the calculations using the SQL function?
- The SQL functions are used to perform the calculations of the statements using the Zend_Db_Select command. - The expression needs to have parentheses and the command that is given as Zend_Db_Select need to provide the statement appropriately. - The Zend_Db_Expr is used to explicitly create the expressions that are given below: $select = $db->select() ->from(array('p' => 'products'), array( 'product_id', 'cost_plus_tax' => new Zend_Db_Expr('p.cost * 1.08'), ));
25What is the way in which the HTML can be used to form elements?
- The form elements can be customized using the decorators and using the Zend_Form for the rendering of the output. - The description decorator can be used to have an instance running that allow the HTML to create the form elements. - The turning of escape characters is required for the output of the decorator and it can be represented as shown below: $element->setDecorators(array( array('ViewHelper'), array('Description', array('escape', false)), array('Errors'), array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), )); - The element can be set to use the description by adding the extra HTML to this and it can be done using this: $element->setDescription('<strong>Hello World</strong>');
26 What is the procedure to see that the optional file is detected?
- There is a use of receive() method that returns true for the file element which is not required. - The file can be neglected when using the method mentioned above, as soon as the file gets opened it detected. - The method returns the false in case of any error or the file hasn’t been copied or uploaded directly. - There are other methods used to provide the detection of the file using the elements in normal HTML file. - The methods can detect the file and provide the tools to make the file being detected.
27 What are the ways in which the file can be detected as being uploaded or not?
- There are certain functions used for the detection of the file and check whether the file is being uploaded properly or not. - The use of isUploaded() function with the pre-defined parameters are used to check and it returns the boolean result. - The use of getFileName() method is used to provide the latest releases of the file and returns the NULL. - The use of getFileInfo() provides a way to make an empty file key that can be used to check whether the file is being uploaded or not. - The flag is set for the isUploaded() method to false that allow the detection to be made easy.
28 What is the use of Zend framework?
- Zend framework is a robust framework that provides the components used by the web applications. - It provides inbuilt libraries and functions to make the programming and integration easier. - Zend framework consists of loosely coupled components that can be used to easily integrate in an application. - It is used for the web application that uses lots of functions and libraries without writing much of the coding. - It provides tools that can be used to have the standalone component based architecture.
29 What is the function of model in MVC architecture?
- MVC is made up of model, view and controller components to, represents the data in the architectural form. - The model component can vary from one requirement to another for MVC application. - The function model represents the application that has the abstract processing of the components. - It uses the zend framework that defines MVC architecture at one place and allow the applications to use it. - It is having the model interface, class and other components that used to identify the value and provide the limitations on the use.
30 Write a program to retrieve the view object within plugin?
- Zend uses the framework that allows easy retrieving of the object within the arbitrary code. - It uses the action helper and other class methods to view the object within the plugin. - The method ViewRenderer() is used by default in the zend framework to view and render the components. $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'; $view = $viewRenderer->view;
31 What is the function of action helper in Zend?
- Zend allows the creation of application using the framework that provides MVC architecture. - The action helper is used to instantiates and store the object i.e Zend_View and other objects that are related to view. - It also provides ways to inject the instantiation process in different objects by the help of action helper. - The view object is stored in the view property provided by the action helper and a view instance is created using this. - ViewRenderer instance is being created using the action helper function and it allows creating sync between all the objects
32 Write a program to show the function of action helper?
- Action helper is used to create the application and instantiate the object of it using the Zend_View. - The object is used and stored using the ViewRenderer’s property that creates an instance and provides more options. - It includes the dispatch process before any action is being dispatched from the view and the example code is given as: if (!isset($viewRenderer->view)) { $viewRenderer->initView(); } $view = $viewRenderer->view;
Zend_Auth
Zend_Auth provides an API for authentication and includes concrete authentication adapters for common use case scenarios, as well as "Identity 2.0" adapters such as OpenID and Microsoft InfoCard.
Zend_Cache
Zend_Cache provides a flexible approach toward caching data, including support for tagging, manipulating, iterating, and removing subsets.
Zend_Console_Getopt
Command-line PHP applications benefit from this convenient object-oriented interface for declaring, parsing, and reporting command-line arguments and options.
Zend_Db
This is a lightweight database access layer, providing an interface to PDO and other database extensions in PHP. It includes adapters for each database driver, a query profiler, and an API to construct most SELECT statements.
Zend_Db_Table The Zend_Db_Table component is a lightweight solution for object-oriented programming with databases.
This component provides a very simple way to work with live syndicated feeds.
Zend_Filter and Zend_Validate
These components encourage the development of secure websites by providing the basic tools necessary for input filtering and validation.
Zend_Filter_Input
This is a configurable solution for declaring and enforcing filtering and validation rules. This component serves as a "cage" for input data, so they are available to your application only after being validated.
Zend_Form
This component provides an object-oriented interface for building forms, complete with input filtering and rendering capabilities.
Zend_Gdata (Zend Google Data Client)
The Google Data APIs provide read/write access to such services hosted at google.com as Spreadsheets, Calendar, Blogger, and CodeSearch.
Zend_Http_Client
This component provides a client for the HTTP protocol, without requiring any PHP extensions. It drives our web services components.
Zend_Json Easily convert PHP structures into JSON and vice-versa for use in AJAX-enabled applications.
Zend_Locale
Zend_Locale is the Framework's answer to the question, "How can the same application be used around the whole world?" This component is the foundation of Zend_Date, Zend_Translate, and others.
Zend_Log
Log data to the console, flat files, or a database. Its no-frills, simple, procedural API reduces the hassle of logging to one line of code and is perfect for cron jobs and error logs.
Zend_Mail and Zend_Mime
Almost every Internet application needs to send email. Zend_Mail, assisted by Zend_Mime, creates email messages and sends them.
Zend_Measure
Using Zend_Measure, you can convert measurements into different units of the same type. They can be added, subtracted, and compared against each other.
supports localized handling of measurements and numbers
supports converting of measurements and numbers
Zend_Memory
Zend_Memory offers an API for managing data in a limited memory mode. A PHP developer can create a Zend_Memory object to store and access large amounts of data, which would exceed the memory usage limits imposed by some PHP environments.
Zend_Registry
The registry is a container for storing objects and values in the application space. By storing an object or value in the registry, the same object or value is always available throughout your application for the lifetime of the request. This mechanism is often an acceptable alternative to using global variables.
Zend_Rest_Client and Zend_Rest_Server
REST Web Services use service-specific XML formats. These ad-hoc standards mean that the manner for accessing a REST web service is different for each service. REST web services typically use URL parameters (GET data) or path information for requesting data and POST data for sending data.
Zend_Search_Lucene
The Apache Lucene engine is a powerful, feature-rich Java search engine that is flexible about document storage and supports many complex query types. Zend_Search_Lucene is a port of this engine written entirely in PHP 5.
Zend_Service: Akismet, Amazon, Audioscrobbler, Delicious, Flickr, Nirvanix, Simpy, StrikeIron and Yahoo!
Web services are important to the PHP developer creating the next generation of mashups and composite applications. Zend Framework provides wrappers for service APIs from major providers to make it as simple as possible to use those web services from your PHP application.
Zend_Session helps manage and preserve session data across multiple page requests by the same client.
Zend_Uri is a component that aids in manipulating and validating Uniform Resource Identifiers (URIs). Zend_Uri exists primarily to service other components such as Zend_Http_Client but is also useful as a standalone utility.
Zend_XmlRpc makes it easy to communicate with and create XML-RPC services from PHP.
mimics PHP's SOAP extension
flexible request and response implementation allows for use with non-HTTP services
server implementation allows attaching existing classes to quickly expose APIs as XML-RPC services
Model View Controller Architecture
MVC Diagram
In MVC pattern, we differentiate our logic(controller), Mysql(model) and html(view). View: It have all the Html parts of the page. Here we use the variables which we have set in controllers. Model: MYSQL queries parts of the page, we make an object of the model in controller & call the functions of the model. after fetching the data, we set it in controller & use in view. Controller: It have all the logic part of the site.
Zend Framework Certification Topics
MVC
Components
Pattern Basics
Bootstrap
Zend_Controller
Zend_Layout
Infrastructure
Zend_Config
Zend_Session
Zend_Registry
Zend_Loader
Internationalization
Zend_Date
Zend_Translate
Zend_Locale
Zend_Currency
Zend_View_Helper_ Translate
Internationalization Performance
Authentication and Access
Zend_Acl
Zend_Auth
Zend_Auth Adapters
Performance
Zend_Cache
Script inclusion
Optimization
Zend_Memory
Forms
Zend_Form
Validation/Filtering
Decorators
Elements
Forms
Display Groups & Sub Forms
Configuration
Internationalization
Security
Cross Site Request Forgery
Secure Authentication
Escaping for output
Cross Site Scripting
Security Best Practices
Diagnosis and Maintainability
Zend_Debug
Zend_Log
Filtering and Validation
Filtering Chains
Custom Filters
Standard Validation Classes
Validator Chains
Custom Validators
search
Zend_Search_Lucene
Indexing
Querying
Performance
Database
Zend_Db
Zend_Db_Statement
Zend_Db_Table
Zend_Db_Profiler
Zend_Db_Select
Table Data Gateway Pattern
Row Data Gateway Pattern
Mail
Constructing
Storage
Message retrieval
Storage providers
Message sending
Coding Standards
Coding conventions
Zend_Loader
Web Services
XML-RPC Client
XML-RPC Server
REST Client
REST Server
Zend_Service Web Services
1. Is Zend Framework 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.
2. What is autoloader?
Autoloader is function that load all the object on start up.
3. What is use of Zend front controller?
2. What is autoloader?
Autoloader is function that load all the object on start up.
3. 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.
4. 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.
5.How you can set Module name, Controller name, and Action name in Zend framework?
$request->setModuleName(‘front’);
$request->setControllerName(‘address’);
$request->setActionName(‘addresslist’);
6.How to configure zend framework application?
Configuration can be done in application.ini file in Zend framework. This file in the path application/configs/application.ini.
7. Checking whether form posted or not in Zend framework?
$request = $this->getRequest();
$getData = $request->getParams();
$postData = $request->getPost();
$isPost = $request->isPost();
8.How to fetch last inserted id, fetch all record,find and fetch a single record.
$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
$this->_db->find($id);
$this->_db->fetchRow($sql);
9.Difference between Zend_Registry and Zend_Session?
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.
10. 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);
11. 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’));
12. Can we call a model in view?
Yes, you can call a model in view. Simple create the object and call the method.
$modelObj = new Application_Model_User();
13.Can we rename the application folder ?
yes, we can
14. Can we move the index.php file outside the public folder?
yes, we can
15. 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();?>
16. 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:
<?=$this->headLink();?>
17. How do you protect your site from sql injection in zend when using select query?
We have to quote the strings,
$this->getAdapter ()->quote ( <variable name> );
$select->where ( ” <field name> = “, <variable name> );
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
11. 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’));
12. Can we call a model in view?
Yes, you can call a model in view. Simple create the object and call the method.
$modelObj = new Application_Model_User();
13.Can we rename the application folder ?
yes, we can
14. Can we move the index.php file outside the public folder?
yes, we can
15. 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();?>
16. 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:
<?=$this->headLink();?>
17. How do you protect your site from sql injection in zend when using select query?
We have to quote the strings,
$this->getAdapter ()->quote ( <variable name> );
$select->where ( ” <field name> = “, <variable name> );
OR (If you are using the question mark after equal to sign)
$select->where ( ” <field name> = ? “, <variable name> );
18. How to Create Form & Form Elements in zend framework?
//create a form object
$form = new Zend_Form
$form->setAction('/resource/process')->setMethod('post');
$form->setAttrib('id', 'login');
//Zend Form support Following form elements
button,
checkbox (one/many),
hidden,
image,
password,
radio,
reset,
select (single select/many select),
submit,
text,
textarea
19. What is Zend_Form?
It uses to create a form in zend framework. In this each input/select/radio/checkbox known as element.
Following are the zend form features.
- Filtering and validation
- Ordering
- Element and Form rendering, including escaping
- Element aSnd form grouping
- Element and form-level configuration
20. List of All Zend Framework Components
Zend_ACL
Zend_Acl provides lightweight and flexible access control list (ACL) functionality and privileges management. In general, an application may utilize such functionality to control access to certain protected objects by other requesting objects.
Resource
creating a Resource is very simple. Zend_Acl provides Zend_Acl_Resource_Interfaceto facilitate developers' creating Resources. A class need only implement this interface, which consists of a single method, getResourceId();
Role
Zend_Acl providesZend_Acl_Role_Interface to facilitate developers' creating Roles. A class need only implement this interface, which consists of a single method, getRoleId(), in order for Zend_Acl to consider the object to be a Role. In Zend_Acl, a Role may inherit from one or more Roles. This is to support inheritance of rules among Role.
Example of ACL
<?php
require_once 'Zend/Acl.php';
$acl = new Zend_Acl();
require_once 'Zend/Acl/Role.php';
$acl->addRole(new Zend_Acl_Role('guest'))
->addRole(new Zend_Acl_Role('member'))
->addRole(new Zend_Acl_Role('admin'));
$parents = array('guest', 'member', 'admin');
$acl->addRole(new Zend_Acl_Role('someUser'), $parents);
require_once 'Zend/Acl/Resource.php';
$acl->add(new Zend_Acl_Resource('someResource'));
$acl->deny('guest', 'someResource');
$acl->allow('member', 'someResource');
echo $acl->isAllowed('someUser', 'someResource') ? 'allowed' : 'denied';
//allowed
?>
// Guest may only view content of all controller, Here 'view' can be an array having all the function which guest may access. null can be a string or an array, Here Null means all controller
$acl->allow($roleGuest, null, 'view');
// Here no controller or action is given, it means Administrator is allowed all privileges $acl->allow('administrator');
// Remove the denial of revising latest news to staff $acl->removeDeny('staff', 'latest', 'revise');
Assertions
Sometimes a rule for allowing or denying a Role access to a Resource should not be absolute but dependent upon various criteria. For example, suppose that certain access should be allowed, but only between the hours of 8:00am and 5:00pm. Another example would be denying access because a request comes from an IP address that has been flagged as a source of abuse.
<?php
require_once 'Zend/Acl/Assert/Interface.php';
class CleanIpaddressAssertion implements Zend_Acl_Assert_Interface
{
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null,
Zend_Acl_Resource_Interface $resource = null, $privilege = null)
{
return $this->_isCleanIP($_SERVER['REMOTE_ADDR']);
}
protected function _isCleanIP($ip)
{
// ...
}
}
$acl->allow(null, null, null, new CleanIpaddressAssertion());
Zend Layout
A website have different pages but have a page where all the footer/header/left/right section is included know as template/layout. Each page is called from that layout. A site may have one or more layout depend on website.
Automate selection and rendering of layouts.
Provide different scope for layout related variables and content.eg render(), partial().
Allow configuration, including layout name, layout script resolution (inflection), and layout.
You can disable layouts, changing layout scripts, and other states; allow these actions from within action controllers and view scripts.
Follow same script resolution rules (inflection) as the ViewRenderer.
There are different options to set the options for layout.
$acl->allow(null, null, null, new CleanIpaddressAssertion());
Zend Layout
A website have different pages but have a page where all the footer/header/left/right section is included know as template/layout. Each page is called from that layout. A site may have one or more layout depend on website.
Automate selection and rendering of layouts.
Provide different scope for layout related variables and content.eg render(), partial().
Allow configuration, including layout name, layout script resolution (inflection), and layout.
You can disable layouts, changing layout scripts, and other states; allow these actions from within action controllers and view scripts.
Follow same script resolution rules (inflection) as the ViewRenderer.
There are different options to set the options for layout.
//static method
Zend_Layout::startMvc($optionArray)
Zend_Layout::startMvc($optionIniObject)
//constructor
$layout = Zend_Layout($optionArray);
$layout = Zend_Layout($optionIniObject);
//methods
$layout = Zend_Layout();
$layout->setOptions($optionArray);
$layout->setOptions($optionIniObject);
//using accessors
$ayout->setLayout('layout)
->setLayoutPath('/views/layouts/mylayout.phtml');
You can use Zend_Layout as an standalone component but in that case all full features will not available. following are available.
Scoping of layout.
isolation of layout view scripts from another view scripts
Zend-Action-Helper
Zend-Action-Helper
A helper can be initialized in several different ways, based on your needs as well as the functionality of that helper. The helper broker is stored as the $_helper member of Zend_Controller_Action; use the broker to retrieve or call on helpers. Some methods for doing so include:
Following are the 3 different but equal method to set the message
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
$flashMessenger->addMessage('We did something in the last request');
OR
$flashMessenger = $this->_helper->FlashMessenger; $flashMessenger->addMessage('We did something in the last request');
OR
$this->_helper->FlashMessenger('We did something in the last request');
Bootstrap:
OR
$flashMessenger = $this->_helper->FlashMessenger; $flashMessenger->addMessage('We did something in the last request');
OR
$this->_helper->FlashMessenger('We did something in the last request');
Bootstrap:
In bootstrap you can setting up the database, configuring your view and view helpers, configuring your layouts, registering plugins, registering action helpers, cron job & service srcipt.
/** Include Bootstrap file in public/index.php */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
/** Include Bootstrap file in public/index.php */
/*in application/bootstrap.php */
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{}
class Zend_Application_Bootstrap_Bootstrap
extends Zend_Application_Bootstrap_BootstrapAbstract{}
abstract class Zend_Application_Bootstrap_BootstrapAbstract
implements Zend_Application_Bootstrap_Bootstrapper,
Zend_Application_Bootstrap_ResourceBootstrapper
21. How to call a function from bootstrap ?
$bootstrap->bootstrap(array('foo'));
In bootstrap class there should be function with name of _initFoo()
$bootstrap->bootstrap(array('foo'));
In bootstrap class there should be function with name of _initFoo()
22. What are the design pattern used in Zend Framework?
Zend Famework mainly use following Patterns.
Singleton Pattern: It is a design pattern that restricts the instantiation of a class to one object.
Example:
class Database {
private static $_singleton;
private $_connection;
private function __construct($host,$user,$pass){
$this->_connection = mysql_connect($host,$user,$pass);
}
public static function getInstance(){
if (is_null (self::$_singleton)) {
self::$_singleton = new Database();
}
return self::$_singleton;
}
}
$db = Database::getInstance();
Factory Pattern:
Factory Pattern:
In this Pattern we can create an instance of any of one class in-directly from an static function of another class.
example
$db = Zend_Db::factory( ...options... );
23 .What is the difference between Zend_Auth and Zend_Acl?
- Zend_Auth provides the authentication protocol for the users using many methods whereas; Zend_Acl is used for authorization purpose. - Zend_Auth uses the methods like LDAP, OpenID and HTTP to provide the authentication, whereas Zend_Acl uses Access Control List for authorization. - Zend_Auth provide the authentication in the form of verifying and providing the credentials for the user’s system, whereas Zend_Acl uses list of roles that is being implemented only those who are authorized to it. - Zend_Auth provides an environment to the system through which user who is authenticated for use, whereas Zend_Acl performs some operations on the specific resources that need to be written on the system. - Zend_Auth supports the authentication platforms features, whereas Zend_Acl supports the advanced definitions with features of multiple inheritance and other similar features.
24 Write a program that performs the calculations using the SQL function?
- The SQL functions are used to perform the calculations of the statements using the Zend_Db_Select command. - The expression needs to have parentheses and the command that is given as Zend_Db_Select need to provide the statement appropriately. - The Zend_Db_Expr is used to explicitly create the expressions that are given below: $select = $db->select() ->from(array('p' => 'products'), array( 'product_id', 'cost_plus_tax' => new Zend_Db_Expr('p.cost * 1.08'), ));
25What is the way in which the HTML can be used to form elements?
- The form elements can be customized using the decorators and using the Zend_Form for the rendering of the output. - The description decorator can be used to have an instance running that allow the HTML to create the form elements. - The turning of escape characters is required for the output of the decorator and it can be represented as shown below: $element->setDecorators(array( array('ViewHelper'), array('Description', array('escape', false)), array('Errors'), array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), )); - The element can be set to use the description by adding the extra HTML to this and it can be done using this: $element->setDescription('<strong>Hello World</strong>');
26 What is the procedure to see that the optional file is detected?
- There is a use of receive() method that returns true for the file element which is not required. - The file can be neglected when using the method mentioned above, as soon as the file gets opened it detected. - The method returns the false in case of any error or the file hasn’t been copied or uploaded directly. - There are other methods used to provide the detection of the file using the elements in normal HTML file. - The methods can detect the file and provide the tools to make the file being detected.
27 What are the ways in which the file can be detected as being uploaded or not?
- There are certain functions used for the detection of the file and check whether the file is being uploaded properly or not. - The use of isUploaded() function with the pre-defined parameters are used to check and it returns the boolean result. - The use of getFileName() method is used to provide the latest releases of the file and returns the NULL. - The use of getFileInfo() provides a way to make an empty file key that can be used to check whether the file is being uploaded or not. - The flag is set for the isUploaded() method to false that allow the detection to be made easy.
28 What is the use of Zend framework?
- Zend framework is a robust framework that provides the components used by the web applications. - It provides inbuilt libraries and functions to make the programming and integration easier. - Zend framework consists of loosely coupled components that can be used to easily integrate in an application. - It is used for the web application that uses lots of functions and libraries without writing much of the coding. - It provides tools that can be used to have the standalone component based architecture.
29 What is the function of model in MVC architecture?
- MVC is made up of model, view and controller components to, represents the data in the architectural form. - The model component can vary from one requirement to another for MVC application. - The function model represents the application that has the abstract processing of the components. - It uses the zend framework that defines MVC architecture at one place and allow the applications to use it. - It is having the model interface, class and other components that used to identify the value and provide the limitations on the use.
30 Write a program to retrieve the view object within plugin?
- Zend uses the framework that allows easy retrieving of the object within the arbitrary code. - It uses the action helper and other class methods to view the object within the plugin. - The method ViewRenderer() is used by default in the zend framework to view and render the components. $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'; $view = $viewRenderer->view;
31 What is the function of action helper in Zend?
- Zend allows the creation of application using the framework that provides MVC architecture. - The action helper is used to instantiates and store the object i.e Zend_View and other objects that are related to view. - It also provides ways to inject the instantiation process in different objects by the help of action helper. - The view object is stored in the view property provided by the action helper and a view instance is created using this. - ViewRenderer instance is being created using the action helper function and it allows creating sync between all the objects
32 Write a program to show the function of action helper?
- Action helper is used to create the application and instantiate the object of it using the Zend_View. - The object is used and stored using the ViewRenderer’s property that creates an instance and provides more options. - It includes the dispatch process before any action is being dispatched from the view and the example code is given as: if (!isset($viewRenderer->view)) { $viewRenderer->initView(); } $view = $viewRenderer->view;
33 What is the function Lucene?
- Lucene is an open source binary format used to have features for high performance and provide other tools to manage the resources. - It provides fully featured text search engine that can be utilized by the applications and be used to execute it. - It provides the storing of the data and the search indexes by providing the standardized query format for querying for other indexes. - Lucene is a search engine provider that allows the functionality to be implemented for the indexes. - Lucene uses the Apache project and having the zend library with the name Zend_Search_Lucene.
34 Why are in-built libraries used for the web services?
- Zend framework is used to solve the development problems of the web applications and it provides resources for use. - Web services are used for the development environment and to make it accessible to all the platforms. - Web services are being provided by the zend framework and used in the application development process. - The users uses the web services to access their work and other services and components. - It uses the Zend_Registry and Zend_Log methods to have the registry setup and log being maintained while setting up the libraries for the web services.
35 What are the steps kept in mind while designing the Zend_Form?
- The markups are placed in the proper places with each element and with the use of form. - The markup should be generated for the displaying of the element and in the form as well. - Inject the values in the element markup with the metadata to design it more effectively. - The reporting errors need to be kept in check to see the repetitive task that is being done using the code. - The form solution is being provided to address the actions and other features that need to be addressed.
36 Write a program to show the instantiation of the window class?
- The decorator is used to extend the functionality of the class that wraps up the structure. - The decorator extends the class and its functionality by wrapping up in a defined pattern. - The use of it allows the user to add or modify the existing behaviour of the API that is same. - Decorators wrap other that identifies the original object and follows with the same API. - The WindowDecorator is being created to display the window, by showing scrollbars, window title, etc; $window = new WindowScrollbarDecorator( new WindowTitleDecorator( new WindowDecorator( new Window() ) ) );
37 What are the methods used in Decorator?
- The methods used to render the view of the final window are shown as: $window->render(); - The render view is being executed by the use of WindowScrollbarDecorator::render() method. - It uses the WindowTitleDecorator::render() method, to be used as the decorator for the title and the rendering of it. - WindowDecorator::render() method, is used as a Decorator of the window class that allow the main execution of the application. - The rendering of the window is being done by using the function or method as: Window::render() that allows the simple use of state object.
38 What is being presented by the Decorators?
- Decorators are used to provide the Zend_Form in the case of developer’s use and provide them the functionality to write the code. - It determines the display and provides the final output of the input that is being provided by the developer. - The solution is being managed by the modified decorator and it is used to decorate the object. - The content can be generated by using the decorate methods and function or using the metadata. - The metadata is being used with the elements or objects through which the content will be generated.
39 What are the basic operations performed by the Decorator?
- Decorator provides the ability to append, prepend, and replace the content that is passed to the method. - The content that is being initially placed provides the empty string and being processed with the decorator. The operations that can be performed are shown below: - Append: this allows the appending of the functions and methods that can be used to build an application. - Prepend: this allows the content to be placed at the beginning of the file. - Replace: this operation will allow the replacement of the content from any of the content that is present.
40 What are the default methods provided by decorators?
- Decorators are used in the application to provide the functionality and make elements to work. - The decorators being provided as default are as follows: - ViewHelper: is a method that allows the viewing of the helper files used. It allows the replacement of the content that is being provided. - Errors: provide the error codes and messages that came during the execution of the application. It provides appending of the content. - HTMLTag: that allows the tags to be written by using the parameters and attributes. It provides the wrapping up of the content and decreasing the length of the code. - Labels: are used to provide the informative keywords as it provides prepending of the content that is being provided.
41 Write a program to show the execution of the application?
- The execution of the program can be done by using the methods of Decorators. - Decorators provide the methods like errors, htmltag, labels, etc. to help the developers to use it and execute their applications. - The program is written like this: $label->render($htmlTag->render($errors->render($viewHelper->render('')))) <input name="hello" id="hello" type="text" value="" /> <div class="error"><ul> <li>...</li> </ul></div> <dd> <input name="hello" id="hello" type="text" value="" /> <div class="error"><ul> <li>...</li> </ul></div> </dd>
42 What are the elements used in customizing the output of using the standard decorators?
The elements used by the decorator to be used in the application are as follows: - ViewHelper: It allows the replacement of the content that is being provided. - Errors: It provides appending of the content. - HtmlTag (
): It provides the wrapping up of the content and decreasing the length of the code. - Label: labels are used with the wrapping of the code using the tag . The form objects are also involved in it and are as follows: - FormElements: are used to iterate the elements, display groups, and sub-forms that are used to render the elements used above.
43 Zend Framework Components
Zend_Acl
Provides lightweight and flexible access control list (ACL) functionality and privileges management. Role: It is an object that may request to access the Resource. Resource: Object which access is controller. e.g. Driver request to access the car. Here driver is Role & Car is resource.
- Lucene is an open source binary format used to have features for high performance and provide other tools to manage the resources. - It provides fully featured text search engine that can be utilized by the applications and be used to execute it. - It provides the storing of the data and the search indexes by providing the standardized query format for querying for other indexes. - Lucene is a search engine provider that allows the functionality to be implemented for the indexes. - Lucene uses the Apache project and having the zend library with the name Zend_Search_Lucene.
34 Why are in-built libraries used for the web services?
- Zend framework is used to solve the development problems of the web applications and it provides resources for use. - Web services are used for the development environment and to make it accessible to all the platforms. - Web services are being provided by the zend framework and used in the application development process. - The users uses the web services to access their work and other services and components. - It uses the Zend_Registry and Zend_Log methods to have the registry setup and log being maintained while setting up the libraries for the web services.
35 What are the steps kept in mind while designing the Zend_Form?
- The markups are placed in the proper places with each element and with the use of form. - The markup should be generated for the displaying of the element and in the form as well. - Inject the values in the element markup with the metadata to design it more effectively. - The reporting errors need to be kept in check to see the repetitive task that is being done using the code. - The form solution is being provided to address the actions and other features that need to be addressed.
36 Write a program to show the instantiation of the window class?
- The decorator is used to extend the functionality of the class that wraps up the structure. - The decorator extends the class and its functionality by wrapping up in a defined pattern. - The use of it allows the user to add or modify the existing behaviour of the API that is same. - Decorators wrap other that identifies the original object and follows with the same API. - The WindowDecorator is being created to display the window, by showing scrollbars, window title, etc; $window = new WindowScrollbarDecorator( new WindowTitleDecorator( new WindowDecorator( new Window() ) ) );
37 What are the methods used in Decorator?
- The methods used to render the view of the final window are shown as: $window->render(); - The render view is being executed by the use of WindowScrollbarDecorator::render() method. - It uses the WindowTitleDecorator::render() method, to be used as the decorator for the title and the rendering of it. - WindowDecorator::render() method, is used as a Decorator of the window class that allow the main execution of the application. - The rendering of the window is being done by using the function or method as: Window::render() that allows the simple use of state object.
38 What is being presented by the Decorators?
- Decorators are used to provide the Zend_Form in the case of developer’s use and provide them the functionality to write the code. - It determines the display and provides the final output of the input that is being provided by the developer. - The solution is being managed by the modified decorator and it is used to decorate the object. - The content can be generated by using the decorate methods and function or using the metadata. - The metadata is being used with the elements or objects through which the content will be generated.
39 What are the basic operations performed by the Decorator?
- Decorator provides the ability to append, prepend, and replace the content that is passed to the method. - The content that is being initially placed provides the empty string and being processed with the decorator. The operations that can be performed are shown below: - Append: this allows the appending of the functions and methods that can be used to build an application. - Prepend: this allows the content to be placed at the beginning of the file. - Replace: this operation will allow the replacement of the content from any of the content that is present.
40 What are the default methods provided by decorators?
- Decorators are used in the application to provide the functionality and make elements to work. - The decorators being provided as default are as follows: - ViewHelper: is a method that allows the viewing of the helper files used. It allows the replacement of the content that is being provided. - Errors: provide the error codes and messages that came during the execution of the application. It provides appending of the content. - HTMLTag: that allows the tags to be written by using the parameters and attributes. It provides the wrapping up of the content and decreasing the length of the code. - Labels: are used to provide the informative keywords as it provides prepending of the content that is being provided.
41 Write a program to show the execution of the application?
- The execution of the program can be done by using the methods of Decorators. - Decorators provide the methods like errors, htmltag, labels, etc. to help the developers to use it and execute their applications. - The program is written like this: $label->render($htmlTag->render($errors->render($viewHelper->render('')))) <input name="hello" id="hello" type="text" value="" /> <div class="error"><ul> <li>...</li> </ul></div> <dd> <input name="hello" id="hello" type="text" value="" /> <div class="error"><ul> <li>...</li> </ul></div> </dd>
42 What are the elements used in customizing the output of using the standard decorators?
The elements used by the decorator to be used in the application are as follows: - ViewHelper: It allows the replacement of the content that is being provided. - Errors: It provides appending of the content. - HtmlTag (
): It provides the wrapping up of the content and decreasing the length of the code. - Label: labels are used with the wrapping of the code using the tag . The form objects are also involved in it and are as follows: - FormElements: are used to iterate the elements, display groups, and sub-forms that are used to render the elements used above.
43 Zend Framework Components
Zend_Acl
Provides lightweight and flexible access control list (ACL) functionality and privileges management. Role: It is an object that may request to access the Resource. Resource: Object which access is controller. e.g. Driver request to access the car. Here driver is Role & Car is resource.
Zend_Auth
Zend_Auth provides an API for authentication and includes concrete authentication adapters for common use case scenarios, as well as "Identity 2.0" adapters such as OpenID and Microsoft InfoCard.
Zend_Cache
Zend_Cache provides a flexible approach toward caching data, including support for tagging, manipulating, iterating, and removing subsets.
Zend_Console_Getopt
Command-line PHP applications benefit from this convenient object-oriented interface for declaring, parsing, and reporting command-line arguments and options.
Zend_Db
This is a lightweight database access layer, providing an interface to PDO and other database extensions in PHP. It includes adapters for each database driver, a query profiler, and an API to construct most SELECT statements.
Zend_Db_Table The Zend_Db_Table component is a lightweight solution for object-oriented programming with databases.
This component provides a very simple way to work with live syndicated feeds.
Zend_Filter and Zend_Validate
These components encourage the development of secure websites by providing the basic tools necessary for input filtering and validation.
Zend_Filter_Input
This is a configurable solution for declaring and enforcing filtering and validation rules. This component serves as a "cage" for input data, so they are available to your application only after being validated.
Zend_Form
This component provides an object-oriented interface for building forms, complete with input filtering and rendering capabilities.
Zend_Gdata (Zend Google Data Client)
The Google Data APIs provide read/write access to such services hosted at google.com as Spreadsheets, Calendar, Blogger, and CodeSearch.
Zend_Http_Client
This component provides a client for the HTTP protocol, without requiring any PHP extensions. It drives our web services components.
Zend_Json Easily convert PHP structures into JSON and vice-versa for use in AJAX-enabled applications.
Zend_Locale
Zend_Locale is the Framework's answer to the question, "How can the same application be used around the whole world?" This component is the foundation of Zend_Date, Zend_Translate, and others.
Zend_Log
Log data to the console, flat files, or a database. Its no-frills, simple, procedural API reduces the hassle of logging to one line of code and is perfect for cron jobs and error logs.
Zend_Mail and Zend_Mime
Almost every Internet application needs to send email. Zend_Mail, assisted by Zend_Mime, creates email messages and sends them.
Zend_Measure
Using Zend_Measure, you can convert measurements into different units of the same type. They can be added, subtracted, and compared against each other.
supports localized handling of measurements and numbers
supports converting of measurements and numbers
Zend_Memory
Zend_Memory offers an API for managing data in a limited memory mode. A PHP developer can create a Zend_Memory object to store and access large amounts of data, which would exceed the memory usage limits imposed by some PHP environments.
Zend_Registry
The registry is a container for storing objects and values in the application space. By storing an object or value in the registry, the same object or value is always available throughout your application for the lifetime of the request. This mechanism is often an acceptable alternative to using global variables.
Zend_Rest_Client and Zend_Rest_Server
REST Web Services use service-specific XML formats. These ad-hoc standards mean that the manner for accessing a REST web service is different for each service. REST web services typically use URL parameters (GET data) or path information for requesting data and POST data for sending data.
Zend_Search_Lucene
The Apache Lucene engine is a powerful, feature-rich Java search engine that is flexible about document storage and supports many complex query types. Zend_Search_Lucene is a port of this engine written entirely in PHP 5.
Zend_Service: Akismet, Amazon, Audioscrobbler, Delicious, Flickr, Nirvanix, Simpy, StrikeIron and Yahoo!
Web services are important to the PHP developer creating the next generation of mashups and composite applications. Zend Framework provides wrappers for service APIs from major providers to make it as simple as possible to use those web services from your PHP application.
Zend_Session helps manage and preserve session data across multiple page requests by the same client.
Zend_Uri is a component that aids in manipulating and validating Uniform Resource Identifiers (URIs). Zend_Uri exists primarily to service other components such as Zend_Http_Client but is also useful as a standalone utility.
Zend_XmlRpc makes it easy to communicate with and create XML-RPC services from PHP.
mimics PHP's SOAP extension
flexible request and response implementation allows for use with non-HTTP services
server implementation allows attaching existing classes to quickly expose APIs as XML-RPC services
Model View Controller Architecture
MVC Diagram
In MVC pattern, we differentiate our logic(controller), Mysql(model) and html(view). View: It have all the Html parts of the page. Here we use the variables which we have set in controllers. Model: MYSQL queries parts of the page, we make an object of the model in controller & call the functions of the model. after fetching the data, we set it in controller & use in view. Controller: It have all the logic part of the site.
Zend Framework Certification Topics
MVC
Components
Pattern Basics
Bootstrap
Zend_Controller
Zend_Layout
Infrastructure
Zend_Config
Zend_Session
Zend_Registry
Zend_Loader
Internationalization
Zend_Date
Zend_Translate
Zend_Locale
Zend_Currency
Zend_View_Helper_ Translate
Internationalization Performance
Authentication and Access
Zend_Acl
Zend_Auth
Zend_Auth Adapters
Performance
Zend_Cache
Script inclusion
Optimization
Zend_Memory
Forms
Zend_Form
Validation/Filtering
Decorators
Elements
Forms
Display Groups & Sub Forms
Configuration
Internationalization
Security
Cross Site Request Forgery
Secure Authentication
Escaping for output
Cross Site Scripting
Security Best Practices
Diagnosis and Maintainability
Zend_Debug
Zend_Log
Filtering and Validation
Filtering Chains
Custom Filters
Standard Validation Classes
Validator Chains
Custom Validators
search
Zend_Search_Lucene
Indexing
Querying
Performance
Database
Zend_Db
Zend_Db_Statement
Zend_Db_Table
Zend_Db_Profiler
Zend_Db_Select
Table Data Gateway Pattern
Row Data Gateway Pattern
Constructing
Storage
Message retrieval
Storage providers
Message sending
Coding Standards
Coding conventions
Zend_Loader
Web Services
XML-RPC Client
XML-RPC Server
REST Client
REST Server
Zend_Service Web Services
Great Job.............
ReplyDeleteGreat Document
ReplyDeleteReally Awesome......
ReplyDeleteThanks for providing these useful questions.. simplified the preparation for interview.
ReplyDeleteNice collections of questions and answer
ReplyDeleteThanks
Arun
php-tutorial-php.blogspot.in