Can you get the db row from the Zend_Validate_Db_Record_Exists validator?

153 views Asked by At

I have a db record exists validator that I call isValid on:

$checkUser=new Zend_Validate_Db_RecordExists(array(
        "table"=>"xxx",
        "field"=>"xxx"
));
$valid=$checkUser->isValid($userID);

Is there anyway I can get the returned row from the db when isValid() is true?

After typing this out I realize I could just query the db, if row exists, great, else its not valid. Still curious about what happens to the data returned from Db_RecordExists though.

1

There are 1 answers

0
Michael Osl On BEST ANSWER

From the source code of Zend_Validate_Db_RecordExists (Version 1.12):

public function isValid($value)
{
    $valid = true;
    $this->_setValue($value);

    $result = $this->_query($value);
    if (!$result) {
        $valid = false;
        $this->_error(self::ERROR_NO_RECORD_FOUND);
    }

    return $valid;
}

So obviously $result is a local variable and consequently it cannot be accessed later on. If you want to achieve that, you could simply write your own validator based Zend_Validate_Db_Abstract.