An overview of the Zend Framework
by Marc Plotz
August 25, 2009
|
Thinking of using a PHP Framework but not sure if it's worth
it? Marc Plotz looks at the bigger picture behind the Zend
Framework.
|
Introduction
Many developers are scared off by the thought of something
as huge and confusing as the Zend Framework - I know this
because I was once one of them. What I soon learned was that
there is some pleasure in working with a framework that does
most of the nauseating grind work for you. However, there is
a trade off: you have to understand the somewhat pedantic
nature of the code required along with the principles of the
design pattern that is MVC (Model-View-Controller). Is it
worth it? Let's take a look.
MVC - What the...
Ok, so you have been coding for years. Loops, dates and
algorithms that go on forever are second nature to you. Why
on Earth would you bother learning a completely new way to
code? Well, its simple: this is not a new way to code, this
is a better way to code and above all, MVC is structured,
ordered and logical once you forget about everyone telling
you about the psuedo-relationship between the controller and
the view.
Thinking of MVC in terms of a design pattern is just crazy.
What you need to think of is that MVC takes the Logic of the
website(The Model) and separates it from the presentational
aspects(The View) and the "thing" that communicates between
the two is the controller. Many articles I have read talk of
something called "Business Logic". I have no idea how to
define this "business logic" in any way that makes sense to
me. How I do think of it is in plain, straight forward
terms: You submit a form, the data is processed, the page
redirects to another location showing perhaps a different
form. That is the essence of MVC. The controller CONTROLS
the VIEW via the MODEL. There is much more to this, but that
is the essence. The model is essentially the database part,
the controller the processor, and the view is presented in
PHP Template files with a phtml extension.
What is important here is that Zend Frameworks MVC Structure
is extremely robust. It is probably the most powerful MVC
structure in the PHP world at the moment, most likely
because Zend Framework is built to handle close to
Enterprise-Class application logic.
Hold itself up by its bootstrap
Bootstrapping refers to a self-sustaining process that
continues without external help. The term is often
attributed to Baron Munchausen, who, in a story called The
Surprising Adventures of Baron Munchausen, pulled himself
out of a swamp by his own bootstraps. In coding talk we say
that bootstrapping is the process of pulling the entire
script through a single file where everything is setup.
Another bonus of Zend Framework is that the site is first
funneled through the root file index.php, from where it is
then bootstrapped outside of the root directory. What this
does is make the entire application inaccessible to anything
except the script itself. The security implications alone
are a bonus, however some things could tend to get hairy
from time to time, especially when it comes to serving
images from below the web root on a shared server. But the
benefits of bootstrapping in this way far outweigh the
negative. Bootstrapping is not only safe, it makes sense.
Set everything up in one place and control the setup from
there.
You have mail, among other things
Yup. Zend makes things simple. From SMTP Mail to Database
queries, it makes it simple and it makes it work without
coding a thousand lines. To me the little things are also
very cool, like pagination--it's as simple as cut and paste
from a template then you customize it the way you like it.
Zend form is not bad, although it will feature a little
later in the "Where they got it wrong" section. Very strong
on the good side are the SESSION sections as
well as simple little things like Flash messenger. Access
control is handled by ZEND_ACL, or Zend
Access Control List. While ACL is not
always simple to understand--trust me it gets tricky--it
works well and does what you need it to. We also have
ZEND_AUTH, which, like the name suggests,
handles authentication simply.
Where they got it wrong
There isn't much that the folks at PHP got wrong, but I have
to say it - THERE IS NOT ENOUGH SUPPORT OUT THERE.
Downloading the manual PDF from framework.zend.com does not
help you much either: it has examples that don't really mean
anything. They show you the absolute bare basics and then
clutter it up with nonsense you will rarely use. The most
disastrous part is definitely Zend Form help. What you want
is a little help with what they call Form Decorators. What
you get is not much. Zend Form Decorators are quite complex
and not really logical to implement, so you would think you
get some support. Alas you don't.
Something I think would be really nice is database support
for forms. I regularly work on a custom framework much
simpler than Zend. What it does have is a good system that
builds database tables according to the structure of forms
throughout the site. It annoyed me a little that I had to
build that functionality into my copy of Zend before I could
really carry on without the hassle of manually building
tables. Trust me, when you build sites that get complex
enough, building tables could take days, especially when
complex table relationships exist.
On the whole
On the whole Zend is a really stable MVC framework that
keeps you coding and learning well into the night. It's
stable, it's powerful and yes, it does take some time to get
used to the setup. But when you do, trust me--you will be
coding with a big smile on your face.
Happy Frameworking
Marc Steven Plotz
|