使用Symfony 1.4的表單,如何在嵌入式表單的驗證器中拋出sfValidatorError?如何在嵌入式表單的驗證器(sfForm)中拋出錯誤
我父窗體調用以下:
public function configure(){
$this->embedForm('page', $pageLinkForm);
}
我的嵌入形式:
public function configure(){
$this->validatorSchema->setPostValidator(new sfValidatorCallback(array(
'callback' => array($this, 'validateLink')
)));
}
public function validateLink($validator, $values) {
if (!empty($values['link']) && !empty($values['outside_link']))
throw new sfValidatorError($validator, 'Only specify either an internal link or an external link, but not both.');
}
的後驗證運行validateLink會拋出sfValidatorError但它並不顯示爲一個全球性的錯誤,並且形式isValid(),但它不應該是。
爲什麼忽略錯誤?我怎樣才能讓它不被忽略?
嘗試debbuging這個文件:http://trac.symfony-project.org/browser/branches/1.4/lib/validator/sfValidatorSchema.class.php(如果可以的話,用XDebug一步一步調試,否則用var_dump())來檢查: - 錯誤sfValidatorError is caugh 驗證 - 由此產生的errorSchema被引發199行 - 它在父窗體上的第159行再次被捕獲 並且請發佈您父窗體的validatorSchema的var_dump() – greg0ire 2010-08-17 19:31:36