我正在尝试为Db_NoRecordExists验证器使用“exclude”选项,因为当我“编辑”该元素时,它总是像往常一样返回“重复”错误.
原文链接:https://www.f2er.com/php/135778.html我的目的是告诉表单保留从Controller传递给表单本身的值…
这是控制器:
public function editAction() { $id = $this->getRequest()->getParam('id'); $pagesMapper = new Application_Model_PagesMapper(); $form = new Application_Form_PageEdit(); $form->populate($pagesMapper->fetchId($id,true)); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { //... cut ... } } $this->view->form = $form; }
这是表格:
class Application_Form_PageEdit extends Zend_Form { public function init() { $commonFilters = array('StringTrim'); $commonValidators = array('NotEmpty'); $this->setMethod('post')->setAction('/admin-page/edit'); $id = new Zend_Form_Element_Hidden('id'); $pid = new Zend_Form_Element_Hidden('pid'); $keyname = new Zend_Form_Element_Text('keyname'); $keyname->setLabel('Keyname') ->setrequired(true) ->addFilters($commonFilters) ->addFilter('StringToLower') ->addFilter('Word_SeparatorToDash') ->addValidator('Db_NoRecordExists',false,array( 'table' => 'pages','field' => 'keyname','exclude' => array( 'field' => 'id','value' => $this->getValue('id) ) ) );
// …切…
一些建议?