»
S
I
D
E
B
A
R
«
Sponsored Links


Zend Framework Architecture
Mar 5th, 2010 by wood

Introduction

Before we begin our exploration of the architecture of the Zend Framework (ZF), it is important to discuss how a typical MVC application is built. Examining and understanding the architecture of an MVC Web application allows you to make more contextually sound choices when building your application.

Three-tier Architecture

The three-tier architecture focuses on defining responsibilities between different parts of the application. It has the following tiers:

Presentation Tier
The top-most level of the application is the UI. The main function of the interface is to translate tasks and results to something the user can understand.

Application Tier
This layer coordinates the application, processes commands, makes logical decisions and evaluations, and performs calculations. It also moves processes data between the two surrounding layers.

Data Tier
Here information is stored and retrieved from a database or file system. The information is then passed back to the logic tier for processing, and then eventually back to the user.

Model-View-Controller Architecture

Although the three-tiers is similar to the MVC architecture, they are different. Conceptually the three-tier architecture is linear. The Presentation tier never communicates directly with the data tier and all communication must pass through the Application tier. However, the MVC architecture is triangular: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model.

Zend Framework

Zend Framework provides components for the MVC and Table Gateway design patterns which are used in most Web applications. Developed by Zend Technologies and released in 2005, Zend Framework is heavily based on the Solar Framework, developed by Paul M. Jones, reason why they share a similar underlying architecture.

There are 3 types of Web application frameworks:

  1. The ones that offer a solid infrastructure: Symfony, Solar, Ruby on Rails and Django.
  2. The ones that offer a component library: ezComponents and PEAR.
  3. The ones that offer both: Zend Framework.

Zend Framework not only offers a solid infrastructure, but also an extensive component library. The component structure of ZF is somewhat unique, each component is designed with few dependencies on other components. This loosely-coupled architecture allows developers to use components individually.

Architecture

The framework architecture is based on the Front Controller and Model-View-Controller architectural patterns:

MVC pattern

The Model is the part of the application that defines its basic functionality behind a set of abstractions. The data access layer and some business logic is defined in the Model. The Views define exactly what is presented to the user. Usually controllers pass data to each view to render in some format. The Controllers bind the whole pattern together. They may manipulate models, decide which view to display based on the user’s request and other factors, pass along the data that each view will need, or hand off control to another controller entirely.

Front Controller pattern

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.

Coupling

ZF provides a loosely-coupled component library simplified to provide most of the functionality everyone needs to develop Web applications. In object-oriented programming coupling or dependency is the degree to which each component relies on each one of the other components. The biggest advantage of a loosely-coupled architecture is that it allows developers to use components individually.

Neil Garb did an excellent job measuring the level of coupling in the Zend Framework based on the number of dependencies set in code. I’ve extended his work by measuring the level of coupling between components set at runtime. I’m using the Inclued extension to trace through the hierarchy of file inclusions and class inheritance at runtime.

The following diagrams where generated using Graphviz:

Zend_Controller dependencies

Zend_Controller and Zend_Db dependencies

Zend_Controller, Zend_Db and Zend_From dependencies

A standard Zend Framework application requires the following components: Zend_Controller, Zend_Uri, Zend_Registry, Zend_Loader, Zend_Config, Zend_Layout, Zend_View, Zend_Filter, Zend_Validate, Zend_Db, Zend_Form and Zend_Exception.

Criticism

Zend Framework is intended to serve as a novel way to manage Web development complexity. Many consider ZF to deliver reasonably well on this promise, however, it does not universally accommodate all design styles, environments or requirements.

Performance

The performance of a framework is influenced by many factors, particularly the configuration of your servers. However, the design of an application can make a big difference and determine whether your site is slow or highly responsive. Recent benchmarks show that the Zend Framework is slower than other Web frameworks.

Although low coupling is a sign of a well-structured system, it may reduce performance, and a highly-coupled system is sometimes desirable to achieve maximum efficiency. Regardless, in many modern frameworks, the cost of reduced performance is often seen as a worthy trade for the benefits to the software development process that result from low coupling.

Design

Although the framework supports modularity, it lacks of some basic features, such as a Module Coordinator. The system doesn’t include any component or configuration mechanism to deal with Model and Controller dependencies, making it very difficult to share modules between applications. Also, Zend_Controller doesn’t allow modular systems to load model files from within its own module as well as outside modules.

The system lacks of local containers to manage object dependencies and interrelationships. Instead, it uses a global container to store objects. According to Troels Knak-Nielsen, the problem with this is that a global container, whether primitive or sophisticated, will always be a global symbol. Most programmers will agree that global variables are bad design, and that goes for a global containers as well.

Namespaces

With PHP 5.3 coming up on the horizon, the Zend Framework API faces a re-design. While namespaces will hopefully lead to more readable code, Zend developers will finally need to start thinking about some standards for abstract classes and interfaces.

Links

Zend_Db_Table subquery
Nov 11th, 2009 by wood

Hi, I have a some SQL that I want to use with ZendFW, but I can't get it working and it's driving me crazy. I get the correct result with this query:

SELECT DISTINCT e.festival_id FROM entries AS e, mail_log as m 
WHERE e.status = 1 
AND e.festival_id 
NOT IN (SELECT m.entry_id FROM entries AS e, mail_log as m WHERE m.entry_id = e.festival_id)

Help would be appreciated. Cheers :)

jQuery/Ajax with Zend Framework
Nov 11th, 2009 by wood

I've been tinkering around with Zend-Framework and Jquery for a month or so, and finally started tinkering with them together using ZendX_JQuery. It seems I've ran into something that at first seemed it should be simple, So maybe I'm just missing something here.

I have a view along the lines of:

$this->ajaxLink( $this->escape($var->title),
                 $this->baseUrl() . "/another/action",
                 array('update' => '#domain' . $var->id ,                      
                	   'complete' => '$("#domain' . $var->id .'").toggle("slow");'));

echo '<div id="domain"' . $var->id . '" style="display:none;" ></div>';

Which works correctly, when the link displayed by the code above is clicked it loads the contents returned from /another/action into the domain"id" div. The problem occurs when the view loaded by the above contains an ajaxLink() the ajax link stops working. This can be fixed by adding an option to the ajaxLink() array "inline" => true but what if I need other JQuery views helpers to work when loaded into the page via ajax i.e. dialogContainer()

Thanks.

Magento checkout
Nov 11th, 2009 by wood

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it?

I'm working on a payment module and have a sort of "cancel" action that i would like to return the user to the step in checkout where you choose the payment method.

I currently return the user to the first step of the checkout like so:

$this->_redirect('checkout/onepage', array('_secure'=>true));
jquery autocomplete and datepicker compatability issue?
Nov 11th, 2009 by wood

Hi,

I have a form that is constructed using ZendX_JQuery_Form, the form contains 2 auto complete inputs and 4 datepickers. The datepickers all worked absolutely fine until I added in the autocomplete fields as well, the autocomplete fields (linking to a backend php action in zend framework) work fine as well but they seem to break the datepicker widgets.

I know very little about JQuery but the javascript that ZF creates seems okay to me:

 $(document).ready(function() {
        $("#firstname").autocomplete({"url":"crm\/candidates\/searchfirstname"});
        $("#lastname").autocomplete({"url":"crm\/candidates\/searchlastname"});
        $("#registeredfrom").datepicker({});
        $("#registeredto").datepicker({});
        $("#updatedfrom").datepicker({});
        $("#updatedto").datepicker({});
 });

Does anyone know of any issues in either JQuery or Zend Framework that or with the code above that might cause this scenario. Also, it would be helpful even if you know there are no issues in either of the frameworks to help me narrow down the search!

Thanks in advance



»  Substance: PHP Frameworks   »  SiteMap