Zend_Form_Element_Text를 유효성 검사기로 확장하는 사용자 정의 양식 요소를 만들려고합니다. 따라서 특정 요소를 사용할 때 유효성 검사기를 계속 설정할 필요가 없습니다. 어쨌든, 내 기본 폼에서 인스턴스화 할 때 $ maxChars 변수를 전달하는 데 문제가 있습니다. 나는이 내가 내 사용자 지정 양식 요소를 인스턴스화 곳입니다변수를 사용자 정의 Zend 양식 요소에 전달
class My_Form_Custom_Element extends Zend_Form_Element_Text
{
public $maxChars
public function init()
{
$this->addValidator('StringLength', true, array(0, $this->maxChars))
}
public function setProperties($maxChars)
{
$this->maxChars= $maxChars;
}
}
아래에있는 내 사용자 정의 요소입니다
아래 내 단축 코드를 제공했습니다.
class My_Form_Abc extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('abc');
$customElement = new My_Form_Custom_Element('myCustomElement');
$customElement->setProperties(100); //**<----This is where i set the $maxChars**
$submit = new Zend_Form_Element_Submit('submit');
$submit -> setAttrib('id', 'submitbutton');
$this->addElements(array($customElement ,$submit));
}
}
내가 '100'을 통과하려고 내 양식에 $ customElement-> SetProperties를 (100)를 사용하여, 그것은 내 StringLength 유효성 검사기에 제대로 전달받을 나던. 유효성 검사기가 Init에서 호출되기 때문에 그것이라고 가정합니다. 이 문제를 어떻게 해결할 수 있습니까?
왜 고마워요, 나는 첫 번째 해결책을 생각하지 않은 이유를 모르겠습니다. 두 번째 해결책은 나에게 새로운 것이지만, 둘 다 잘 작동합니다. 환호 =) – user322003