Friday, March 19. 2010
Brandon Savage approached me
with an interesting issue regarding ZF bootstrap resources, and accessing
them in your action controllers. Basically, he'd like to see any resource
initialized by the bootstrap immediately available as simply a public member
of his action controller.
So, for instance, if you were using the "DB" resource in your application,
your controller could access it via $this->db.
Continue reading "A Simple Resource Injector for ZF Action Controllers"
Thursday, March 11. 2010
I see a number of questions regularly about module bootstraps in Zend
Framework, and decided it was time to write a post about them finally.
In Zend Framework 1.8.0, we added Zend_Application, which is
intended to (a) formalize the bootstrapping process, and (b) make it
re-usable. One aspect of it was to allow bootstrapping of individual
application modules -- which are discrete collections of controllers, views,
and models.
The most common question I get regarding module bootstraps is:
Why are all module bootstraps run on every request, and not just the one for
the requested module?
To answer that question, first I need to provide some background.
Continue reading "Module Bootstraps in Zend Framework: Do's and Don'ts"
Thursday, February 4. 2010
In my last
article, I wrote about how to get started with
Zend_Application, including some information about how to write
resource methods, as well as listing available resource plugins. What
happens when you need a re-usable resource for which there is no existing
plugin shipped? Why, write your own, of course!
All plugins in Zend Framework follow a common
pattern. Basically, you group plugins under a common directory, with a
common class prefix, and then notify the pluggable class of their location.
For this post, let's consider that you may want a resource plugin to do the
following:
- Set the view doctype
- Set the default page title and title separator
Continue reading "Creating Re-Usable Zend_Application Resource Plugins"
Tuesday, December 30. 2008
In the last two entries in this series on models, I covered
using forms as input filters
and integrating ACLs into models.
In this entry, I tackle some potential infrastructure for your models.
The Model is a complex subject. However, it is often boiled down to either a
single model class or a full object relational mapping (ORM). I personally
have never been much of a fan of ORMs as they tie models to the underlying
database structure; I don't always use a database, nor do I want
to rely on an ORM solution too heavily on the off-chance that I later need
to refactor to use services or another type of persistence store. On the
other hand, the model as a single class is typically too simplistic.
Continue reading "Model Infrastructure"
Wednesday, December 24. 2008
In my last post, I discussed using Zend_Form as a combination input filter/value object within your models.
In this post, I'll discuss using Access Control Lists (ACLs) as part of your
modelling strategy.
ACLs are used to indicate who has access to do what
on a given resource. In the paradigm I will put forward, your
resource is your model, and the what are the various
methods of the model. If you finesse a bit, you'll have "user" objects that
act as your who.
Just like with forms, you want to put your ACLs as close to your domain
logic as possible; in fact, ACLs are part of your domain.
Continue reading "Applying ACLs to Models"
Monday, December 22. 2008
A number
of blog
posts
have sprung up lately in the Zend Framework community discussing the Model
in the Model-View-Controller pattern.
Zend Framework has never had a
concrete Model class or interface; our stand has been that models are
specific to the application, and only the developer can really know what
would best suit it.
Many other frameworks tie the Model to data access -- typically via the
ActiveRecord
pattern or a Table Data Gateway
-- which completely ignores the fact that this is tying the Model to the
method by which it is persisted. What happens later if you start using
memcached? or migrate to an SOA architecture? What if, from the very
beginning, your data is coming from a web service? What if you do
use a database, but your business logic relies on associations
between tables?
While the aforementioned posts do an admirable job of discussing the various
issues, they don't necessarily give any concrete approaches a developer
can use when creating their models. As such, this will be the first
in a series of posts aiming to provide some concrete patterns and techniques
you can use when creating your models. The examples will primarily be
drawing from Zend Framework components, but should apply equally well to a
variety of other frameworks.
Continue reading "Using Zend_Form in Your Models"
Thursday, September 11. 2008
Now that Zend_Test
has shipped, developers are of course asking, "How do I setup my test
suite?" Fortunately, after some discussion with my colleagues and a little
experimenting on my one, I can answer that now.
Continue reading "Setting up your Zend_Test test suites"
Monday, June 30. 2008
Since I originally started hacking on the Zend Framework MVC in the fall of
2006, I've been touting the fact that you can test ZF MVC projects by
utilizing the Request and Response objects; indeed, this is what I actually
did to test the Front Controller and Dispatcher. However, until recently,
there was never an easy way to do so in your userland projects; the default
request and response objects make it difficult to easily and quickly setup
tests, and the methods introduced into the front controller to make it
testable are largely undocumented.
So, one of my ongoing projects the past few months has been to create an
infrastructure for functional testing of ZF projects using PHPUnit. This past weekend, I made the
final commits that make this functionality feature complete.
The new functionality provides several facets:
- Stub test case classes for the HTTP versions of our Request and Response
objects, containing methods for setting up the request environment
(including setting GET, POST, and COOKIE parameters, HTTP request
headers, etc).
Zend_Dom_Query, a class for using CSS selectors (and XPath)
to query (X)HTML and XML documents.
- PHPUnit constraints that consume
Zend_Dom_Query and the
Response object to make their comparisons.
- A specialized PHPUnit test case that contains functionality for
bootstrapping an MVC application, dispatching requests, and a variety of
assertions that utilize the above constraints and objects.
Continue reading "Testing Zend Framework MVC Applications"
Wednesday, May 21. 2008
I'm pleased to announce that
Zend Framework will be partnering
with Dojo Toolkit to deliver
out-of-the-box Ajax and rich user interfaces for sites developed in Zend
Framework.
First off, for those ZF users who are using other Javascript toolkits: Zend
Framework will continue to be basically JS toolkit agnostic. You will still
be able to use whatever toolkit you want with ZF applications. ZF will
simply be shipping Dojo so that users have a toolkit by default. Several
points of integration have been defined, and my hope is that these can be
used as a blueprint for community contributions relating to other javascript
frameworks. In the meantime, developers choosing to use Dojo will have a
rich set of components and integration points to work with.
The integration points we have defined for our initial release are as
follows:
Continue reading "Zend Framework Dojo Integration"
Monday, May 5. 2008
As a continuing part of my MVC series, I've posted a new article on
Form Decorators
up on the DevZone.
I'm hoping this will be the definitive guide to using form decorators. I
cover the design decisions behind them, basics of operation, how to
customize output by mixing and matching standard decorators, and how to
create your own custom decorators. Among the examples are how to create a
table-based layout for your forms (instead of the dynamic list layout used
by default), and how to use a View Script as your form decorator in order to
have full control over your form layout.
So, if you've been playing with Zend_Form and having trouble wrapping your
head around decorators, give it a read!
|
|