// 해결책 Zends Sourcecode를 검색하는 동안 (질문하기 전에 ...) 내가 제일 좋은 해결책을 찾았습니다.Validator에서 필드를 추출하는 최선의 방법
//Inside Controller before valling $form->isValid()
$form->getElement('x')->getValidator('Db_NoRecordExists')->setExclude(array(
'field'=>'some_id',
'value'=>$idToEdit
))
// 초기 질문 내가 Zend_Form을 확장을 통해 내 양식을 만들 : 추상 DB 검증 클래스는 setExclude()
그래서 우리는 그 다음 좋은 흐름에서 사용할 수있는 기능을 얻었다. 그리고 나는 addAction()
과 editAction()
에 하나의 양식을 사용합니다. 편집 프로세스 내에서 요소를 제거하려면 $form->removeElement('x')
을 통해 쉽게 수행 할 수 있습니다.
하지만 유효성 검사기에서 필드를 제거하는 최선의 방법은 무엇입니까?
1) 분리 폼
//Forms Contstructor
public function __construct($idToEdit=0, $options=null)
{
$this->setIdToEdit($idToEdit);
parent::__construct($options);
}
//within init()
$formField->addValidator('Db_NoRecordExists', true, array(
'table'=>'table',
'field'=>'field',
'exclude'=>array(
'field'=>'id',
'value'=>$this->getIdToEdit()
)
));
//Controller calling the form like this:
$form = new Custom_Form($this->_getParam('id'), $options);
3) 다른 무언가로 편집 ID 주입 새롭게 설정된 검증
//Controllers editAction()
$form->removeValidator('Db_NoRecordExists');
$form->addValidator('Db_NoRecordExists', true, array(
'table'=>'table',
'field'=>'field',
'exclude'=>array(
'field'=>'id',
'value'=>$this->_getParam('id')
)
));
2)를 추가? 어쩌면 두 가지 아이디어가 나에게 너무 잘 보이지 않지만 어쨌든 두 가지 아이디어가 너무 잘 보이지는 않을지 모르지만 어쨌든 내가 놓친 다른 것이있다 : S 어쨌든, 모든 입력은 감사하겠습니다. :)