本文整理汇总了PHP中Zend\Form\Form::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::bind方法的具体用法?PHP Form::bind怎么用?PHP Form::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setModel
/**
* @param mixed $model
*/
public function setModel($model)
{
$modelClass = get_class($model);
$this->form = $this->annotationBuilder->createForm($modelClass);
$this->form->bind($model);
$this->setVariables(['form' => $this->form, 'object' => $model, 'title' => $this->getFieldSetTitle($model)]);
$this->buildFormViewModel($this->form, $this);
}
示例2: getNoteForm
/**
* @param Entity\Note $note
* @param string $url
* @param string $action
* @param array $members
* @return \Zend\Form\Form
*/
public function getNoteForm(Entity\Note $note, $url = '', $action = 'add', $members = null)
{
if (is_null($this->noteForm)) {
$builder = new AnnotationBuilder($this->getEntityManager());
$this->noteForm = $builder->createForm($note);
$this->noteForm->setAttribute('action', $url);
$this->noteForm->setAttribute('id', 'noteForm');
$this->noteForm->setHydrator(new DoctrineObject($this->getEntityManager(), 'Secretary\\Entity\\Note'));
$this->noteForm->bind($note);
if ($action == 'edit' && $note->getPrivate() === false) {
$this->noteForm->remove('private');
$group = $note->getGroup();
$membersString = $this->getMembersString(array_keys($members));
$this->noteForm->get('groupHidden')->setValue($group->getId());
$this->noteForm->get('members')->setValue($membersString);
$this->noteForm->getInputFilter()->remove('__initializer__');
$this->noteForm->getInputFilter()->remove('__cloner__');
$this->noteForm->getInputFilter()->remove('__isInitialized__');
$this->noteForm->getInputFilter()->remove('lazyPropertiesDefaults');
} else {
$this->noteForm->get('private')->setAttribute('required', false);
$this->noteForm->getInputFilter()->get('private')->setRequired(false);
}
}
return $this->noteForm;
}
示例3: create
/**
* Create a new post
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create($data, &$form)
{
$post = new PostEntity();
$em = $this->getEntityManager();
$form->bind($post);
$form->setData($data);
if (!$form->isValid()) {
return false;
}
// we rename the file with a unique name
$newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
foreach (PostEntity::$thumbnailVariations as $variation) {
$result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
if (!$result) {
$this->message = $result;
return false;
}
}
$post->setThumbnail($newName);
$post->setPostDate("now");
$post->setUrl($this->getPostUrl($post));
try {
$em->persist($post);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
return false;
}
}
示例4: bind
/**
* Bind an object to the form
*
* Ensures the object is populated with validated values.
* Set isEditForm to true so that edit form is distinguished
*
* @param object $object
* @param int $flags ,default value is FormInterface::VALUES_NORMALIZED
* @param bool $isEditForm ,default value is true
* @return mixed|void
* @throws Exception\InvalidArgumentException
*/
public function bind($object, $flags = FormInterface::VALUES_NORMALIZED, $isEditForm = true)
{
if ($isEditForm === true) {
$this->isEditForm = true;
}
parent::bind($object, $flags);
}
示例5: create
/**
* Create a new image
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create($data, &$form)
{
$entity = new ImageEntity();
$em = $this->getEntityManager();
$form->bind($entity);
$form->setData($data);
if (!$form->isValid()) {
return false;
}
// we rename the file with a unique name
$newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
foreach (ImageEntity::$thumbnailVariations as $variation) {
$result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
if (!$result) {
$this->message = $result;
return false;
}
}
$entity->setImage($newName);
try {
$em->persist($entity);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
return false;
}
}
示例6: testPreserveEntitiesBoundToCollectionAfterValidation
public function testPreserveEntitiesBoundToCollectionAfterValidation()
{
$this->form->setInputFilter(new \Zend\InputFilter\InputFilter());
$fieldset = new TestAsset\ProductCategoriesFieldset();
$fieldset->setUseAsBaseFieldset(true);
$product = new Entity\Product();
$product->setName('Foobar');
$product->setPrice(100);
$c1 = new Entity\Category();
$c1->setId(1);
$c1->setName('First Category');
$c2 = new Entity\Category();
$c2->setId(2);
$c2->setName('Second Category');
$product->setCategories(array($c1, $c2));
$this->form->add($fieldset);
$this->form->bind($product);
$data = array('product' => array('name' => 'Barbar', 'price' => 200, 'categories' => array(array('name' => 'Something else'), array('name' => 'Totally different'))));
$hash1 = spl_object_hash($this->form->getObject()->getCategory(0));
$this->form->setData($data);
$this->form->isValid();
$hash2 = spl_object_hash($this->form->getObject()->getCategory(0));
// Returned object has to be the same as when binding or properties
// will be lost. (For example entity IDs.)
$this->assertTrue($hash1 == $hash2);
}
示例7: bind
/**
* (non-PHPdoc)
*
* @see \Zend\Form\Form::bind()
*/
public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
{
if (null != $object->getId() && null != $this->get('submit')) {
$this->get('submit')->setAttribute('value', 'BTN_UPDATE');
}
parent::bind($object, $flags);
}
示例8: bind
public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
{
foreach ($this->getFieldsets() as $fieldset) {
$fieldset->setObject($object);
}
$result = parent::bind($object, $flags);
return $result;
}
示例9: updateAction
public function updateAction()
{
if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
$this->seoForm->bind($seo);
if ($this->request->isPost()) {
$this->seoForm->setData($this->request->getPost());
if ($this->seoForm->isValid()) {
$this->seoService->update($this->seoForm->getData());
$this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
}
$view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
$view->setTerminal(true);
return $view;
}
示例10: getForm
/**
* Returns a form for the current entity with an input filter set
* built using the provided annotations in model
*
* @return Form
*/
public function getForm()
{
if (empty($this->form)) {
$builder = new AnnotationBuilder();
$this->form = $builder->createForm($this);
$this->form->bind($this);
}
return $this->form;
}
示例11: getForm
/**
* @return \Zend\Form\Form
*/
public function getForm($entity)
{
if ($this->form->hasValidated()) {
return $this->form;
}
$this->form->bind($entity);
$this->form->bindOnValidate();
$this->getEventManager()->trigger($this->createEvent(CrudEvent::FORM_READY, $this->form));
return $this->form;
}
示例12: login
/**
* @param \Zend\Form\Form $form
* @param $data
* @return bool
*/
public function login(&$form, $data)
{
$user = new User();
$form->bind($user);
$form->setData($data);
if ($form->isValid()) {
return true;
} else {
return false;
}
}
示例13: createFromForm
/**
* createFromForm
*
* @param Form $form
* @return CdliTwoStageSignup\Model\EmailVerification
*/
public function createFromForm(Form $form)
{
$form->bind(new Model());
if (!$form->isValid()) {
return false;
}
$model = $form->getData();
$model->generateRequestKey();
$this->getEventManager()->trigger(__FUNCTION__, $this, array('record' => $model, 'form' => $form));
$this->getEmailVerificationMapper()->insert($model);
return $model;
}
示例14: editAction
/**
* Edit
*
* @return ViewModel
*/
public function editAction()
{
$object = $this->getObject();
if ($this->form) {
$this->form->bind($object);
}
$request = $this->getRequest();
if ($request->isPost()) {
if ($response = $this->processForm()) {
return $response;
}
}
$viewModel = new ViewModel();
$viewModel->setTemplate($this->templates['edit']);
$viewModel->setVariables(array('form' => $this->form, 'object' => $object, 'templates' => $this->templates, 'routes' => $this->routes));
return $viewModel;
}
示例15: bind
public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
{
parent::bind($object, $flags);
$pluginClasses = $this->getAttribute(static::BIND_PLUGIN_CLASSES);
if (!empty($pluginClasses)) {
if (!is_array($pluginClasses)) {
throw new \InvalidArgumentException('The plugin classes attribute must be an array');
}
foreach ($pluginClasses as $pluginClass) {
if (!is_subclass_of($pluginClass, '\\Zork\\Form\\Plugin\\BindInterface')) {
throw new \InvalidArgumentException('The plugin class must be implement \\Zork\\Form\\Plugin\\BindInterface');
}
$plugin = new $pluginClass();
$plugin->bind($this);
}
}
return $this;
}