本文整理汇总了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);
}