제 양식에는 데이터베이스 테이블에서 고유해야하는 foo
필드가 있습니다. 그래서 나는 그것의 유효성 검사기 목록에 Zend\Validator\Db\NoRecordExists
추가 : 다른 필드에 종속 된 필드 유효성 검사를 만드는 방법 ZF2에서 usind array form setup을 사용 하시겠습니까?
namespace Bar\Form\Fieldset;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Db\Adapter\AdapterInterface;
class BuzFieldset extends Fieldset implements InputFilterProviderInterface
{
protected $dbAdapter;
public function __construct($name = null, $options = []) {...}
public function setDbAdapter(AdapterInterface $dbAdapter) {...}
public function init()
{
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add(
[
'name' => 'foo',
'type' => 'text',
'options' => [...],
'attributes' => [
'required' => 'required',
'class' => 'form-control'
]
]);
...
}
public function getInputFilterSpecification()
{
return [
'foo' => [
'required' => true,
'validators' => [
[
'name' => 'Regex',
'options' => [
'pattern' => '/.../',
'message' => _(...)
]
],
[
'name' => 'Zend\Validator\Db\NoRecordExists',
'options' => [
'table' => 'buz',
'field' => 'foo',
'adapter' => $this->dbAdapter
]
]
]
],
...
];
}
}
가 지금은 검증 양식을 얻을 수없는 항목을 업데이트하기위한 물론 동일한 양식을 사용하고 싶습니다. 그래서
id
필드에 따라이 필드에 대한
NoRecordExists
확인을해야합니다.
id
이 설정되면 (즉, 업데이트가 아니라 생성 중임) 모든 유효성 검사기 (예 : 여기
Regex
)가 적용되어야하지만이 것은 유효하지 않습니다. 그렇게하는 방법?
정말 고마워요! – automatix