Pages

Monday 23 July 2012

Zend Interview Questions and Answers

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.

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.

How you can set Module name, Controller name, and Action name in Zend framework?
  •  $request->setModuleName(‘front’);
  •  $request->setControllerName(‘address’);
  •  $request->setActionName(‘addresslist’); 

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.

Checking whether form posted or not in Zend framework?
$request = $this->getRequest();
$getData = $request->getParams();
$postData = $request->getPost(); 
$isPost = $request->isPost();


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

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.

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


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

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

Can we rename the application folder ?
yes, we can

Can we move the index.php file outside the public folder?
yes, we can

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


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

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

What is zend framework?
Answer: It is opensource framework created by zend.com (PHP company). It is object oriented and follow the MVC. Zend Framework is focused on building more secure, reliable and fast development.

How to add extra HTML (i.e link) in Zend_Form?
Answer: use Desciption decorator with (escape =false in second parameter).

How can I detect if an optional file has been uploaded?
Answer:  Zend_File_Transfer_Adapter_Http's receive()  return true.

What is Zend registry?
Answer: It is container for object and values  in applications, when you set an object in zend_registry you can access in whole site.

What is Zend_Form?
Answer: It is mainly used to display the form. but along with this we use for filter, validation and formating our form. It have following elements
Element filter
Element validation
Element ordering.
Decorator
Grouping
Sub form
Rendering form elments in single call or one by one for elements.

What is zend helpers?
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).


What do you know about zend layout.
Answer: It work as a site template and have following features.
                Automatic selection and rendering layout
                Provide separate scope for calling element i.e parital, render, partialLoop

What is Inflection?
Answer: 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.

What is Front Controller?
Answer:  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 Zend_filter?
Zend_filter is used to filter the data as remove the tags, trailing the spaces, remove all except digits.

Friday 20 July 2012

Create Form & Form Elements


//create a form object
$form = new Zend_Form
$form->setAction('/resource/process')
     ->setMethod('post');

$form->setAttrib('id', 'login');
?>


//Form support Following elements
button,
checkbox (one/many),
hidden,
image,
password,
radio,
reset,
select (single select/many select),
submit,
text,
textarea

Thursday 19 July 2012

Zend Framework Central Authentication

Zend Framework Central Authentication


  • Zend Framework  follow MVC Design with Dispatcher.
  • Auth / ACL Implement
  • Validate & Filter the URL with using dispatcher

class FilterPlugin extends Zend_Controller_Plugin_Abstract

public function preDispatch(Zend_Controller_Request_Abstract $request) 

    $params     = $request->getParams(); 
    $controller = $request->getControllerName(); 
    $action     = $request->getActionName(); 
    $filter = $GLOBALS['filters'][$controller][$action]; 
    $validator = $GLOBALS['validators'][$controller][$action]; 
    $inputdata = new Zend_Filter_Input($filter, $validator, $params); 
    if (!$inputdata ->isValid()) { 
        $request->setModuleName('default') 
                ->setControllerName('error') 
                ->setActionName('illegalparam') 
                ->setDispatched(false); 
        return; 
    } 
}


Wednesday 18 July 2012

Sitemap

  • Zend Interview Questions And Answers (1)
    • Zend Interview Questions And Answers
      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 alo...
       
  • Zend Dom Query (1)
    • Zend Dom Query Examples
          $htmlData ='    <h3>      <img src="wow/img.jpg" /><a href="http://wow.com">wow link</a>     </h3>    <h3>      <img src="wow/img.jpg" ><a href="http://wow.com">wow link2<...
       
  • Zend Acl (1)
    • 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_Ac...
       
  • Zend_Form (2)
    • Create Form & Form Elements
      //create a form object$form = new Zend_Form$form->setAction('/resource/process')     ->setMethod('post');$form->setAttrib('id', 'login');?>//Form support Following elementsbutton,checkbox (one/many),hidden,image,password,radio,reset,select (single select/many select),submi...
       
    • 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·    &...
       
  • Zend Framework Security (2)
    • ZF Security Escaping For Output
      $this->escape($foo) in view files...
       
    • Zend Framework Central Authentication
      Zend Framework Central AuthenticationZend Framework  follow MVC Design with Dispatcher.Auth / ACL ImplementValidate & Filter the URL with using dispatcherclass FilterPlugin extends Zend_Controller_Plugin_Abstract{ public function preDispatch(Zend_Controller_Request_Abstract $request)&n...
       
  • MVC (7)
    • 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 layo...
       
    • Zend_Controller
      Zend_Controller is the heart of Zend Framework's MVC system. Zend_Controller_Front implements a "Front Controller" pattern, in which all requests are intercepted by the front controller and dispatched to individual Action Controllers based on the URL requested.Zend_Controller_Front also implements t...
       
    • 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 ...
       
    • Bootstrap
      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.ph...
       
    • Design Patern
      Design Patern: It a formal way of documenting a solution to a problem.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 $_connect...
       
    • Components
      Zend_AclProvides 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. ...
       
    • 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 & cal...
       
  • Zend Authentication And Authorization (1)
    • Zend Auth
      Zend_AuthZend_Auth is concerned only with authentication and not with authorization. Authentication is loosely defined as determining whether an entity actually is allowed or not....
       
  • Site Map (1)
    • Sitemap
      Loading... @import url("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css"); function LoadDynamicFeedControl() { var feeds = [ {title: 'Zend Framework Certification', url: 'http://zend-framework-certification.blogspot.com/rss.xml?redirect=false&start-index=1&max-results=999'...
       

Tuesday 17 July 2012

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

Sunday 8 July 2012

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




















Sunday 1 July 2012

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_Controller


Zend_Controller is the heart of Zend Framework's MVC system. Zend_Controller_Front implements a "Front Controller" pattern, in which all requests are intercepted by the front controller and dispatched to individual Action Controllers based on the URL requested.Zend_Controller_Front also implements the Singleton pattern, meaning only a single instance of it may be available at any given time. The Zend_Controller system is designed to be lightweight, modular, and extensible

Zend Controller Diagram

 The Zend_Controller workflow is implemented by several components.









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