0

What is the best practice to validate on multiple values when using a custom Zend Validator? Currently I am passing in an array as $value, but this seems awkward and not very extendable to me. Would there be a better way? Here is a snippet of my validator.:

public function isValid($value=array())
{
    $userID=$value["userID"];
    $applicationID=$value["applicationID"];

    /***** Validate next and return, etc.
Chris Mitchell
  • 634
  • 10
  • 28

1 Answers1

0

If you validate userID and applicationID in the same way (same rules), so just call isValid method twice. There is nothing wrong with it.

If they have different rules, create two different validator classes. It would follow basic separation of logic.

Gediminas
  • 854
  • 8
  • 14
  • Not trying to validate userID/applicationID per say, but trying to validate if user exists, for example. So the validator needs two arguments. Probably a bad example but I think the question is still valid, whats the best way to validate based on multiple values? – Chris Mitchell Mar 04 '13 at 21:48
  • I would simply do in the same way as I've said half a year ago - create validator classes/use default ones for each data type (lets say user id is a data type) and then call one by one. I don't like the array approach because you might end up with validator classes used only in one case - not reusable. – Gediminas Mar 05 '13 at 00:03