I have overriddend the isValid()
function for a form, and I was wondering if there are any drawbacks to adding logic there.
Example code:
public function isValid($data)
{
// conditional requirement of fields
$isValid = parent::isValid($data);
if ($isValid) {
// additional 开发者_运维问答validation
}
return $isValid;
}
No, none. But I'd put an if statement around the parent:
$parentIsValid = parent::isValid($data);
if($parentIsValid) {
//Extra stuff, you may as well only do this if the parent valid function returns true
//Set isValid var in here
} else $isValid = false;
return $isValid;
精彩评论