本文整理汇总了PHP中Zend\Form\FormInterface::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::bind方法的具体用法?PHP FormInterface::bind怎么用?PHP FormInterface::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateAction
public function updateAction()
{
$request = $this->getRequest();
$recipe = $this->readService->findById($this->params('id'));
if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
throw new UnauthorizedException('Insufficient Permissions');
}
$viewModel = new ViewModel();
$viewModel->setTemplate('recipe/update');
$viewModel->setVariables(['form' => $this->form]);
$this->form->bind($recipe);
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
try {
$this->writeService->save($this->form->getData());
$this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert');
$this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]);
} catch (\Exception $e) {
var_dump($e->getMessage());
}
}
}
$this->layout('layout/backend');
return $viewModel;
}
示例2: manageAction
public function manageAction()
{
if (false === $this->authorizationService->isGranted('user.admin')) {
throw new UnauthorizedException('Insufficient Permissions');
}
$userId = $this->params('id', null);
if (null === $userId) {
return $this->listUsers();
}
$userObject = $this->userService->findById($userId);
if (false === $userObject instanceof UserEntity) {
return $this->listUsers();
}
$request = $this->getRequest();
$viewModel = new ViewModel();
$viewModel->setTemplate('user/update');
$viewModel->setVariables(['form' => $this->form]);
$this->form->bind($userObject);
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
try {
$this->userService->save($this->form->getData());
$this->flashMessenger()->addSuccessMessage('User successfully updated');
return $this->redirect()->toRoute('zfcuser/manage');
} catch (\Exception $e) {
var_dump($e->getMessage());
}
} else {
var_dump($this->form->getMessages());
}
}
return $viewModel;
}
示例3: updateAction
public function updateAction()
{
$person = $this->contactService->findPerson($this->params('id'));
if (!$person) {
return $this->notFoundAction();
}
$this->contactForm->bind($person);
if ($this->getRequest()->isPost()) {
$this->contactForm->setData($this->getRequest()->getPost());
if ($this->contactForm->isValid()) {
$person = $this->contactService->persistContact($this->contactForm->getData());
return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_PERSON, 'id' => $person->getId()->toString()]);
}
}
return new ViewModel(['person' => $person, 'contactForm' => $this->contactForm]);
}
示例4: updateAction
public function updateAction()
{
$company = $this->contactService->findCompany($this->params('id'));
if (!$company) {
return $this->notFoundAction();
}
$this->contactForm->bind($company);
if ($this->getRequest()->isPost()) {
$this->contactForm->setData($this->getRequest()->getPost());
if ($this->contactForm->isValid()) {
$company = $this->contactService->persistContact($this->contactForm->getData());
return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_COMPANY, 'id' => $company->getId()->toString()]);
}
}
return new ViewModel(['company' => $company, 'contactForm' => $this->contactForm]);
}
示例5: editAction
public function editAction()
{
$client = $this->clientRepository->find($this->params('clientId'));
if ($client === null) {
$this->getResponse()->setStatusCode(404);
return;
}
$this->clientForm->bind($client);
if ($this->getRequest()->isPost()) {
$this->clientForm->setData($this->getRequest()->getPost());
if ($this->clientForm->isValid()) {
$this->clientService->persist($this->clientForm->getData());
$this->redirect()->toRoute('clients/show', ['clientId' => $client->getId()]);
}
}
return new ViewModel(['form' => $this->clientForm]);
}
示例6: editAction
/**
* @return \Zend\Http\Response|ViewModel
*/
public function editAction()
{
$request = $this->getRequest();
$post = $this->postService->findPost($this->params('id'));
$this->postForm->bind($post);
if ($request->isPost()) {
$this->postForm->setData($request->getPost());
if ($this->postForm->isValid()) {
try {
$this->postService->savePost($this->postForm->getData());
return $this->redirect()->toRoute('blog');
} catch (\Exception $e) {
}
}
}
return new ViewModel(array('form' => $this->postForm));
}
示例7: updateAction
public function updateAction()
{
$cronjob = $this->cronManager->find($this->params('id'));
if (!$cronjob) {
return $this->notFoundAction();
}
$this->cronjobForm->bind($cronjob);
if ($this->getRequest()->isPost()) {
$this->cronjobForm->setData($this->getRequest()->getPost());
if ($this->cronjobForm->isValid()) {
$data = $this->cronjobForm->getData();
$this->cronManager->persist($data);
return $this->redirect()->toRoute('admin/system/cron');
}
}
return new ViewModel(['cronjob' => $cronjob, 'cronjobForm' => $this->cronjobForm]);
}
示例8: editAction
public function editAction()
{
$project = $this->projectRepository->find($this->params('projectId'));
if ($project === null) {
$this->getResponse()->setStatusCode(404);
return;
}
$this->projectForm->get('client')->setValue($project->getClient()->getName());
$this->projectForm->bind($project);
if ($this->getRequest()->isPost()) {
$this->projectForm->setData($this->getRequest()->getPost());
if ($this->projectForm->isValid()) {
$this->projectService->persist($this->projectForm->getData());
$this->redirect()->toRoute('clients/show', ['clientId' => $project->getClient()->getId()], ['fragment' => 'project-table']);
}
}
return new ViewModel(['form' => $this->projectForm]);
}
示例9: updateAction
public function updateAction()
{
/** @var \ZourceUser\Entity\Account $account */
$account = $this->accountTaskService->find($this->params('id'));
if (!$account) {
return $this->notFoundAction();
}
$this->accountForm->bind($account);
if ($this->getRequest()->isPost()) {
$this->accountForm->setData($this->getRequest()->getPost());
if ($this->accountForm->isValid()) {
$account = $this->accountForm->getData();
$this->accountTaskService->persist($account);
return $this->redirect()->toRoute('admin/usermanagement/accounts');
}
}
return new ViewModel(['account' => $account, 'accountForm' => $this->accountForm]);
}
示例10: updateAction
public function updateAction()
{
$group = $this->groupTaskService->find($this->params('id'));
if (!$group) {
return $this->notFoundAction();
}
$this->groupForm->bind($group);
if ($this->getRequest()->isPost()) {
$this->groupForm->setData($this->getRequest()->getPost());
if ($this->groupForm->isValid()) {
$group = $this->groupForm->getData();
$this->groupTaskService->persist($group);
$this->flashMessenger()->addSuccessMessage('The group has been updated.');
return $this->redirect()->toRoute('admin/usermanagement/groups');
}
}
return new ViewModel(['group' => $group, 'groupForm' => $this->groupForm]);
}
示例11: getForm
/**
* get form
*
* @param int $id
* @return \Zend\Form\FormInterface
*/
public function getForm($id = 0)
{
if ((int) $id > 0) {
$entity = $this->find($id);
if ($entity) {
$this->form->bind($entity);
}
}
return $this->form;
}
示例12: updateAction
public function updateAction()
{
$application = $this->applicationService->getApplication($this->params('id'));
if (!$application) {
return $this->notFoundAction();
}
if ($application->getAccount() !== $this->zourceAccount()) {
return $this->notFoundAction();
}
$this->applicationForm->bind($application);
if ($this->getRequest()->isPost()) {
$this->applicationForm->setData($this->getRequest()->getPost());
if ($this->applicationForm->isValid()) {
$updatedApplication = $this->applicationForm->getData();
$this->applicationService->persistApplication($updatedApplication);
return $this->redirect()->toRoute('settings/applications');
}
}
return new ViewModel(['application' => $application, 'applicationForm' => $this->applicationForm]);
}
示例13: editAction
public function editAction()
{
$request = $this->getRequest();
$page = $this->pageService->findPage($this->params('id'));
$this->pageForm->bind($page);
if ($request->isPost()) {
$this->pageForm->setData($request->getPost());
if ($this->pageForm->isValid()) {
try {
$this->pageService->savePage($page);
return $this->redirect()->toRoute('admin');
} catch (\Exception $e) {
// Some DB Error happened
$view = new ViewModel(array('message' => $e->getMessage()));
$view->setTemplate('error/error');
return $view;
}
}
}
return new ViewModel(array('form' => $this->pageForm));
}
示例14: mapEntity
/**
* Maps entity property to forms or child containers.
*
* @param \Zend\Form\FormInterface $form
* @param \Core\Entity\EntityInterface $entity
* @param string $property
* @return void
*/
protected function mapEntity($form, $entity, $property)
{
if (false === $property) {
return;
}
if (true === $property) {
$mapEntity = $entity;
} else {
if ($entity->hasProperty($property) || is_callable([$entity, "get{$property}"])) {
$getter = "get{$property}";
$mapEntity = $entity->{$getter}();
} else {
return;
}
}
if ($form instanceof Container) {
$form->setEntity($mapEntity);
} else {
$form->bind($mapEntity);
}
}
示例15: bindForm
protected function bindForm(FormInterface $form)
{
$form->setAttribute('type', 'create');
$id = $this->getIdentifier();
if ($id !== false) {
$entity = $this->entityService->getEntityByIdentifier($id);
if (!$entity) {
//404
}
$form->setAttribute('type', 'edit');
} else {
$entityClass = $this->entityClass;
$entity = new $entityClass();
}
$form->bind($entity);
return $form;
}