Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top