本文整理汇总了PHP中Symfony\Component\Form\Form::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::bind方法的具体用法?PHP Form::bind怎么用?PHP Form::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bindRequest
/**
* @param Request $request
*/
public function bindRequest(Request $request)
{
$this->form->bind($request);
foreach ($this->tabs as $tab) {
$tab->bindRequest($request);
}
}
示例2: process
/**
* @param EntityManager $user
*
* @return bool
*/
public function process(ProjetModel $projet)
{
$this->form->setData($projet);
if ('POST' == $this->request->getMethod()) {
$this->form->bind($this->request);
if ($this->form->isValid()) {
$projet->setUser($this->connectedUser);
############ Edit settings ##############
$DestinationDirectory = __DIR__ . '/../../../../../web/uploads/';
//specify upload directory ends with / (slash)
$Quality = 90;
//jpeg quality
##########################################
//Let's check allowed $ImageType, we use PHP SWITCH statement here
$ext = $projet->file->getMimeType();
switch (strtolower($projet->file->getMimeType())) {
case 'image/png':
//Create a new image from file
$CreatedImage = imagecreatefrompng($projet->file->getRealPath());
break;
case 'image/gif':
$CreatedImage = imagecreatefromgif($projet->file->getRealPath());
break;
case 'image/jpeg':
case 'image/pjpeg':
$CreatedImage = imagecreatefromjpeg($projet->file->getRealPath());
break;
default:
die('Unsupported File!');
//output error and exit
}
// Crop and save image to upload directory
$cropService = $this->cropper;
$destImage = uniqid() . '.' . $projet->file->guessExtension();
if (!$cropService->cropImage($projet->getX(), $projet->getY(), $projet->getW(), $projet->getH(), $DestinationDirectory . $destImage, $CreatedImage, $Quality, $projet->file->getMimeType())) {
die('Erreur lors du rognage de l\'image');
}
$projet->setPhoto($destImage);
// Create entity project
$entity = new Projet();
$entity->setNomprojet($projet->getNomprojet());
$entity->setDescription($projet->getDescription());
$entity->setDuree($projet->getDuree());
$entity->setDaterealisation($projet->getDaterealisation());
$entity->setGains($projet->getGains());
$entity->setFinancement($projet->getFinancement());
$entity->setPhoto($projet->getPhoto());
$entity->setCout($projet->getCout());
$entity->setUser($projet->getUser());
$this->entityManager->persist($entity);
$this->entityManager->flush();
return true;
}
}
return false;
}
示例3: process
/**
*
* @return boolean
*/
public function process()
{
$this->form->bind($this->request);
if ($this->form->isValid()) {
$formData = $this->form->getData();
if ($name = (string) $formData->name) {
$this->qb->andWhere($this->qb->expr()->like('a.name', ':name'))->setParameter('name', '%' . $name . '%');
}
return true;
}
return false;
}
示例4: checkFilters
/**
* checkFilters
*
* Build filters form
* If the method POST filters are constructed and written to the session
* else if in session is a form of filter-it is Otherwise,
* if there is a default filters-they are
*
* @param array $default (stand default filter (option))
* @return
*/
protected function checkFilters($default = array())
{
if ($this->filter_fields) {
$this->filter_form = $this->createForm(new BuilderFormFilterType($this->filter_fields));
if (count($default)) {
$this->filter_form->setData($default);
}
$method = $this->query instanceof NativeQuery ? 'buildNativeQuery' : 'buildQuery';
if ($this->get('request')->getMethod() == 'POST') {
$this->get('session')->remove('_filter_' . $this->get('request')->get('_route'));
$this->get('session')->remove('_pager_' . $this->get('request')->get('_route'));
$this->filter_form->bind($this->get('request'));
$this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
$filterService = $this->get('zk2_admin_panel.form_filter_session');
$filterService->serialize($this->filter_form->getData(), '_filter_' . $this->get('request')->get('_route'));
} elseif ($this->get('session')->has('_filter_' . $this->get('request')->get('_route'))) {
$filterService = $this->get('zk2_admin_panel.form_filter_session');
$data = $filterService->unserialize('_filter_' . $this->get('request')->get('_route'), $this->em_name);
$this->filter_form->setData($data);
$this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
} elseif (count($default)) {
$this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
}
}
}
示例5: process
/**
* @param UserInterface $user
*
* @return bool
*/
public function process(UserInterface $user)
{
$this->form->setData($user);
if ('POST' == $this->request->getMethod()) {
$this->form->bind($this->request);
if ($this->form->isValid()) {
$this->onSuccess($user);
return true;
}
// Reloads the user to reset its username. This is needed when the
// username or password have been changed to avoid issues with the
// security layer.
$this->userManager->reloadUser($user);
}
return false;
}
示例6: process
/**
* Processes the form with the request
*
* @param Form $form
* @return Message|false the sent message if the form is bound and valid, false otherwise
*/
public function process(Form $form)
{
if ('POST' !== $this->request->getMethod()) {
return false;
}
$form->bind($this->request);
if ($form->isValid()) {
return $this->processValidForm($form);
}
return false;
}
示例7: handle
/**
* @param Form $form
* @param Request $request
* @param array $options
*
* @return bool
*/
public function handle(Form $form, Request $request, array $options = null)
{
if (!$request->isMethod('POST')) {
return false;
}
$form->bind($request->request->get($form->getName()));
if (!$form->isBound() || !$form->isValid()) {
return false;
}
$this->usermanager->createUser($form->getData()->getUser());
return true;
}
示例8: testDataIsInitializedFromBind
public function testDataIsInitializedFromBind()
{
$mock = $this->getMockBuilder('\\stdClass')->setMethods(array('preSetData', 'preBind'))->getMock();
$mock->expects($this->at(0))->method('preSetData');
$mock->expects($this->at(1))->method('preBind');
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addEventListener(FormEvents::PRE_SET_DATA, array($mock, 'preSetData'));
$config->addEventListener(FormEvents::PRE_BIND, array($mock, 'preBind'));
$form = new Form($config);
// no call to setData() or similar where the object would be
// initialized otherwise
$form->bind('foobar');
}
示例9: testFalseIsConvertedToNull
public function testFalseIsConvertedToNull()
{
$mock = $this->getMockBuilder('\\stdClass')->setMethods(array('preBind'))->getMock();
$mock->expects($this->once())->method('preBind')->with($this->callback(function ($event) {
return null === $event->getData();
}));
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addEventListener(FormEvents::PRE_BIND, array($mock, 'preBind'));
$form = new Form($config);
$form->bind(false);
$this->assertTrue($form->isValid());
$this->assertNull($form->getData());
}
示例10: process
/**
*
* @access public
* @return bool
*/
public function process()
{
$this->getForm();
if ($this->request->getMethod() == 'POST') {
$this->form->bind($this->request);
// Validate
if ($this->form->isValid()) {
if ($this->getSubmitAction() == 'post') {
$formData = $this->form->getData();
$this->onSuccess($formData);
return true;
}
}
}
return false;
}
示例11: validateForm
protected function validateForm(Form $form, $request_data)
{
$form->bind($request_data);
if (!$form->isValid()) {
$msg = $form->getErrors();
if (sizeOf($msg)) {
$msg = array_map(function ($message) {
return $message->getMessage();
}, $msg);
$msg = "\n- " . implode("\n- ", $msg);
} else {
$msg = "\n- " . $form->getErrorsAsString();
}
$this->get('logger')->err('Erreur formulaire: ' . $msg);
throw new InvalidArgumentException($msg);
}
}
示例12: process
/**
* {@inheritDoc}
*/
public function process(Request $request, Form $form, UserResponseInterface $userInformation)
{
$user = $this->userManager->createUser();
// Try to get some properties for the initial form when coming from github
if ('GET' === $request->getMethod()) {
$user->setUsername($this->getUniqueUsername($userInformation->getNickname()));
if ($userInformation instanceof AdvancedUserResponseInterface) {
$user->setEmail($userInformation->getEmail());
}
}
$form->setData($user);
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$randomPassword = $this->tokenGenerator->generateToken();
$user->setPlainPassword($randomPassword);
$user->setEnabled(true);
$apiToken = substr($this->tokenGenerator->generateToken(), 0, 20);
$user->setApiToken($apiToken);
return true;
}
}
return false;
}
示例13: filterNate
/**
* Takes a form and query builder and returns filtered and paginated entities
* @param QueryBuilder $filterBuilder
* @param Form $form
* @param string $session_key
* @param int $limit
* @param int $page_number
*
* @return mixed
*/
public function filterNate($filterBuilder, &$form, $session_key, $limit = 5, $page_number = 1)
{
$em = $this->container->get('doctrine')->getManager();
$paginator = $this->container->get('knp_paginator');
$lexik = $this->container->get('lexik_form_filter.query_builder_updater');
$session = $this->container->get('session');
$request = $this->container->get('request');
if ($request->getMethod() == "POST") {
// bind values from the request
$form->bind($request);
// build the query from the given form object
$session->set("filternator_{$session_key}", $form->getData());
} else {
if ($session->has("filternator_{$session_key}")) {
$data = $session->get("filternator_{$session_key}");
$this->manageObjects($data, $em);
$form->setData($data);
}
}
$lexik->addFilterConditions($form, $filterBuilder);
$entities = $filterBuilder->getQuery()->getResult();
$pagination = $paginator->paginate($entities, $request->query->get('page', $page_number), $limit);
return $pagination;
}
示例14: testMultipartFormsWithParentsRequireNoFiles
public function testMultipartFormsWithParentsRequireNoFiles()
{
$form = new Form('author', new Author(), $this->validator);
$form->add($this->createMultipartMockField('file'));
$form->setParent($this->createMockField('group'));
// files are expected to be converted by the parent
$form->bind(array('file' => 'test.txt'));
}
示例15: testSubformAlwaysInsertsIntoArrays
public function testSubformAlwaysInsertsIntoArrays()
{
$ref1 = new Author();
$ref2 = new Author();
$author = array('referenceCopy' => $ref1);
$form = new Form('author', array('validator' => $this->createMockValidator()));
$form->setData($author);
$refForm = new FormTest_FormThatReturns('referenceCopy');
$refForm->setReturnValue($ref2);
$form->add($refForm);
$form->bind($this->createPostRequest(array('author' => array('referenceCopy' => array()))));
// the new reference was inserted into the array
$author = $form->getData();
$this->assertSame($ref2, $author['referenceCopy']);
}