Zend Developer Zone
Where the ElePHPants come to learn

Zend Developer Zone

Aaron Saray talks about View scripts for Zend_Form in ZF1

VERY Old Content Warning!

The content you are viewing is more than two years old. It is here for archival purposes. Do not use any advice in this article without double-checking it with a current source.


Over on his blog, Aaron Saray has written an interesting tutorial titled “Using custom view scripts for Zend_Form in ZF1“. Here’s a quick clip to give you a taste.


I think it’s important to start out with the purpose of the Zend Form component. Often, I run into developers who look at Zend Form as a giant helper class. They don’t distance the concept of the logic and the view. In fact, Zend Form is really a complete HTML form generation package, complete with separate logic and views.

The purpose of the logical part of Zend Form is to process input. If you really dissect the methods, you’ll notice that most (if not all) do not rely on the actual submission of a form. Simply, they accept an input and “run” the form based on that. Notice I said “run” and not render. For example, when you call isValid() you are executing the form logic. Generally, people will send in Zend_Http_Request::getPost() or something like that. However, you could easily parse an array from an incoming REST submission, an array representation of another object, or any number of sources.

The purpose of the view component of the Zend Form is to develop a quick way of rendering the output of a created/processed form object. These views come with the form, but are not required. We can set our own views if we really want to. But more on that later…

As it turns lout, later isn’t that much farther down the page. This isn’t a long-form tutorial, more of a quick hit. Aaron gives you both the HOW and the WHY in a very no-nonsense blog post. Don’t worry, there’s code that you can cut-n-paste if you just want the answer (You probably looked in the back of the book for answers in grade school as well, didn’t you.)

Zend_Form is one of the more complex and difficult components in Zend Framework 1 and as such, it’s always good to see someone showing others what they’ve learned. Drop by Aaron’s blog and give the post a read. make sure you leave him a comment if you like what you read.

Many moons ago, at the tender age of 14, Cal touched his first computer. (We're using the term "computer" loosely here, it was a TRS-80 Model 1) Since then his life has never been the same. He graduated from TRS-80s to Commodores and eventually to IBM PC's. For the past 10 years Cal has worked with PHP and MySQL on Linux OSX, and when necessary, Windows. He has built on a variety of projects ranging in size from simple web pages to multi-million dollar web applications. When not banging his head on his monitor, attempting a blood sacrifice to get a particular piece of code working, he enjoys building and managing development teams using his widely imitated but never patented management style of "management by wandering around". Cal is happily married to wife 1.31, the lovely and talented Kathy. Together they have 2 kids who were both bright enough not to pursue a career in IT. Cal blogs at http://blog.calevans.com and is the founder and host of Nomad PHP