Handling mail and mime in PHP using the Zend Framework

Handling mail is a very common requirement in web applications. Even the most basic sites usually have a contact form that sends a mail through the server instead of putting a contact mail address for spam-spiders to find. Using PHP’s built in function (aptly named mail() ) is relatively straightforward – until you need slightly more advanced features, such as adding and encoding email headers or sending multiple mails efficiently.
Continue reading Handling mail and mime in PHP using the Zend Framework

Passing arrays to Zend_Controller_Router

WARNING: The following contains unsanctioned HACKS to the Zend Framework. Use at your own discretion.

A big advantage to using the front controller in the Zend Framework is the ability to create nicely formatted urls. Instead of an ugly GET string we can pass parameters as slash delimited key -> value pairs. For example:
www.techfounder.com/index.php?post=passing_arrays&comment=3 can be replaced with www.techfounder.com/post/passing_arrays/comment/3
(On techfounder this is actually performed via mod_rewrite rules, but the principle is the same).

The implementation of the default router in the Zend Framework (Zend_Controller_Router_Rewrite) does not allow for passing arrays in this manner though, since previously set keys get overwritten if they are declared more than once. This is somewhere between semi-annoying to very annoying, so lets get straight to hacking it into submission.
Continue reading Passing arrays to Zend_Controller_Router

Pagination with Zend_Db_Select

Pages, by googleA common (web) interface feature is to divide a long list of items into numbered pages, a technique called pagination. I’ll describe in brief some shortcuts I use with Zend_Db_Select to retrieve the row count and calculate the number of pages for complicated queries.
Continue reading Pagination with Zend_Db_Select

Models In The Zend Framework – Part 2

Continuing with this series, we’ll get right to business.

Filtering and validation

Filtering and validation are the basics of dealing with user input in the web. We filter data before passing it to the database to prevent attacks (such as SQL Injections) and we validate user input to make sure it is what we expect it to be (hence, valid).

I will be using the Zend_Filter and Zend_Validate components to deal with those two tasks, and combine their usage via the Zend_Filter_Input component. Zend_Filter and Zend_Validate are self explanatory, however I will cover Zend_Filter_Input in brief.

Continue reading Models In The Zend Framework – Part 2