-- Joe Czhlobatnik <yogl...@hotmail.com> wrote (on Monday, 17 August 2009, 10:05 AM -0400): > > > It seems that it's not possible to alias validators in the manner one can > alias > > > decorators. Is there any way to use multiple validators of the same type > > > on > a > > > single field without extending the class to rename it? > > > > Can you present a use case? > > > > Validators (and filters) are usually very, very specific in what they > > do, and running the same validator multiple times would be redundant. > > For this reason, there's been no functionality to do aliased validators > > or filters. > > I can see how this makes no sense for all validators, save one > -- Db_NoRecordExists. I simply want to check a field against more than one > table. > > Let's say I have one table that contains existing users and one that contains > banned usernames. I don't want to have to populate a complete user record and > then set it to be invalid just for the sake of banning a particular username. > > Or (my actual case) I have one table that contains info for validated and > active users, and one that contains info for not yet validated new user > requests. They're in two separate tables because the request table contains > much more information than the user table, but once the account is approved, > that information is no longer needed. So rather than keep that useless info > around in the user table, there are two separate tables, and the associated > request record gets deleted when the new user gets approved. What I'd like to > do is have the "request a new username" form abort if there is an existing > username or a pending request for that username.
In this particular case, I'd create a Zend_Validate object and attach several Db_(No)RecordExists validators to it -- then attach the master object to your form. This gives you the benefit of multiple validators and eliminates the need for Aliases. $chain = new Zend_Validate(); $foo = new Zend_Validate_Db_NoRecordExists(...); $bar = new Zend_Validate_Db_NoRecordExists(...); $chain->addValidator($foo) ->addValidator($bar); $element->addValidator($chain); -- Matthew Weier O'Phinney Project Lead | matt...@zend.com Zend Framework | http://framework.zend.com/