本文整理匯總了PHP中Zend\Form\Form::setBindOnValidate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::setBindOnValidate方法的具體用法?PHP Form::setBindOnValidate怎麽用?PHP Form::setBindOnValidate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Form\Form
的用法示例。
在下文中一共展示了Form::setBindOnValidate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: create
/**
* Create a new gallery
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create(&$data, &$form)
{
$entity = new GalleryEntity();
$em = $this->getEntityManager();
if (isset($data['gallery']['images'])) {
$data['gallery']['images'] = json_decode($data['gallery']['images'], true);
}
$form->bind($entity);
$form->setData($data);
$form->setBindOnValidate(Form::BIND_MANUAL);
if (!$form->isValid()) {
return false;
}
$entity->setName($data['gallery']['name']);
$entity->setUrl($this->getGalleryUrl($entity));
if (isset($data['gallery']['parentGallery']) && !empty($data['gallery']['parentGallery'])) {
$parent = $this->getGalleryRepository()->find($data['gallery']['parentGallery']);
if ($parent) {
$entity->setParentGallery($parent);
}
}
// WHY THE FUCK DO I HAVE TO FLUSH HERE
$em->persist($entity);
$em->flush();
foreach ($data['gallery']['images'] as $join) {
$image = $this->getImageRepository()->find($join['joinId']);
if ($image) {
$galleryImage = new GalleryImage($join['title'], $join['position']);
$image->addGalleries($galleryImage);
$entity->addImages($galleryImage);
}
}
try {
$em->persist($entity);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_NOT_CREATED"]);
return false;
}
}
示例2: testSetBindOnValidateWrongFlagRaisesException
public function testSetBindOnValidateWrongFlagRaisesException()
{
$this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
$this->form->setBindOnValidate(Form::VALUES_AS_ARRAY);
}