Tag Archives: Software framework

Cool tutorial about Zend_Paginator

Every part of Zend Framework is indeed very profesional and useful. But as it happens often some modules are less used than others. Don’t know why but my feeling is that Zend_Paginator, a wonderful tool for pagination is really misunderstood. And in fact it does one of the most common web development tasks. It builds the abstraction for a component that everybody uses in a web project – pagination.

It make sense if there where more tutorials like the following one describing its usage! Many thanks to Joey Rivera for a great tutorial about Zend_Paginator.

Even more this tutorials goes behind the pure usage of the paginator but it helps you understand the integration with one of the most used web apps today – Twitter and another Zend Framework component – Zend_Cache.

joey rivera blog

Using Zend Framework validators – Zend_Validate_Db_RecordExists

What are validators?

In very very breve these are methods which can validate some data, usually user input, against some specific rules. Imagine there’s a web form that is always checked for empty fields or some fields that may contain valid e-mail addresses. This is so common that became everyday routine to almost all of us. However smart developers make abstractions that help them reuse all this functionality. Even smarter developers make use of frameworks. And for those of you, using Zend Framework, there’s no need to write most of the common used validators, simply because they come with the framework itself.

Technically you’ve various validators in zend, such as Zend_Validate_Alnum, Zend_Validate_Email or Zend_Validate_Regex. All these are extremely useful when it comes to automatic, bullet proof validation, but I’m going to talk more about one specific validator.

Zend_Validate_Db_RecordExists

Although the implementation is nothing more than just a chunk of code and doesn’t pretend to be difficult, the idea of such validator is genius indeed. It really helps you do some amazing job.

Image you have to check some database record existence. Then comes in help this validator. In fact I’m pretty sure almost everyone has experience with such kind of task. Simply because the registration process almost always requires it. When you try to register new user you more often check for the username existence. Although you may solve the problem with other technique by catching the exception the database is throwing for duplicate entries, this should be assumed just as an example.

I’m pretty sure this validator can be really useful in many occasions!

Redirecting with Zend Framework – part 2

Recently I posted about the redirecting mechanism of Zend Framework. It’s a working chunk of code but the problem is that it seems quite difficult in according with other ZF sample codes.

Yes the same goal can be achieved with less effort. Like the _forward function which just executes other action/controller, you can call the _redirect method to rewrite the URI.

Just use that in any action of any controller:

$this->_redirect('http://www.example.com');

That executes exactly the same as calling the header PHP method or echoing the <meta> refresher!