本文整理汇总了PHP中Zend\Form\FormInterface::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::setData方法的具体用法?PHP FormInterface::setData怎么用?PHP FormInterface::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::setData方法的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: indexAction
public function indexAction()
{
$request = $this->getRequest();
$logContent = '';
// initialize when no submit anymore
$data = [];
$data['logmessage'] = $this->form->get('logmessage')->getValue();
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
$data = $this->form->getData();
$this->loggerPriority = $data['logpriority'];
if ($data['logformat'] !== 'simple') {
$this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat'];
unset($this->loggerConfig['writers'][0]['options']['formatter']['options']);
}
}
}
$logger = new Logger($this->loggerConfig);
// save log data to buffer and make it variable
ob_start();
$logger->log((int) $this->loggerPriority, $data['logmessage']);
$logContent = ob_get_clean();
return new ViewModel(['form' => $this->form, 'logContent' => $logContent]);
}
示例4: createAction
public function createAction()
{
if ($this->getRequest()->isPost()) {
$this->dashboardForm->setData($this->getRequest()->getPost());
if ($this->dashboardForm->isValid()) {
$data = $this->dashboardForm->getData();
$this->dashboardTaskService->persistFromArray($data);
return $this->redirect()->toRoute('dashboard/manage');
}
}
return new ViewModel(['dashboardForm' => $this->dashboardForm]);
}
示例5: indexAction
public function indexAction()
{
$request = $this->getRequest();
$formMessages = [];
$isPost = false;
if ($request->isPost()) {
$this->form->setData($request->getPost());
$this->form->isValid();
$formMessages = $this->form->getMessages();
$isPost = true;
}
return new ViewModel(['form' => $this->form, 'formMessages' => $formMessages, 'isPost' => $isPost]);
}
示例6: indexAction
/**
*
* @return ViewModel|Response
*/
public function indexAction()
{
if (!is_null($this->identity())) {
return $this->redirect()->toRoute($this->loginRedirectRoute);
}
if ($this->getRequest()->isPost()) {
$this->loginForm->setData($this->getRequest()->getPost());
if ($this->loginForm->isValid()) {
return $this->redirect()->toRoute($this->loginRedirectRoute);
}
}
return new ViewModel(array('loginForm' => $this->loginForm));
}
示例7: indexAction
public function indexAction()
{
$this->settingsForm->setData($this->settingsManager->getAll());
if ($this->getRequest()->isPost()) {
$this->settingsForm->setData($this->getRequest()->getPost());
if ($this->settingsForm->isValid()) {
$data = $this->settingsForm->getData();
$this->settingsManager->set('application_title', $data['application_title']);
$this->settingsManager->flush();
$this->flashMessenger()->addSuccessMessage('The settings have been saved.');
return $this->redirect()->toRoute('admin/system/settings');
}
}
return new ViewModel(['settingsForm' => $this->settingsForm]);
}
示例8: 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]);
}
示例9: 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]);
}
示例10: changesAction
public function changesAction()
{
$siteId = $this->services->getUtilityService()->getSiteId();
$site = $this->services->getSiteService()->find($siteId);
$fromControl = $this->dateIntervalForm->get(DateIntervalForm::FROM_DATE_NAME);
$toControl = $this->dateIntervalForm->get(DateIntervalForm::TO_DATE_NAME);
$lastDate = $site->getLastUpdate();
$lastDate->setTime(23, 59, 59);
$fromControl->setAttribute('max', $lastDate->format('Y-m-d'));
$toControl->setAttribute('max', $lastDate->format('Y-m-d'));
$from = clone $lastDate;
$from->sub(new \DateInterval('P1M'));
$to = $lastDate;
$fromControl->setValue($from->format('Y-m-d'));
$toControl->setValue($to->format('Y-m-d'));
$request = $this->getRequest();
if ($request->isPost()) {
$this->dateIntervalForm->setData($request->getPost());
if ($this->dateIntervalForm->isValid()) {
$from = \DateTime::createFromFormat('Y-m-d', $fromControl->getValue());
$to = \DateTime::createFromFormat('Y-m-d', $toControl->getValue());
}
}
$from->setTime(0, 0, 0);
$to->setTime(23, 59, 59);
$result = array('intervalForm' => $this->dateIntervalForm, 'site' => $site, 'members' => $this->getMembersData($siteId, $from, $to), 'pages' => $this->getPagesData($siteId, $from, $to), 'revisions' => $this->getRevisionsData($siteId, $from, $to), 'votes' => $this->getVotesData($siteId, $from, $to));
return new ViewModel($result);
}
示例11: resetPasswordAction
public function resetPasswordAction()
{
$code = $this->params('code');
if ($code) {
$this->resetPasswordForm->get('code')->setValue($code);
}
if ($this->getRequest()->isPost()) {
$this->resetPasswordForm->setData($this->getRequest()->getPost());
if ($this->resetPasswordForm->isValid()) {
$data = $this->resetPasswordForm->getData();
$this->passwordChanger->resetAccountPassword($data['code'], $data['credential']);
return $this->redirect()->toRoute('login');
}
}
return new ViewModel(['resetPasswordForm' => $this->resetPasswordForm, 'code' => $code]);
}
示例12: indexAction
/**
* Use the form to get barcode image from selected barcode object.
*/
public function indexAction()
{
$request = $this->getRequest();
//default value without post parameter
$barcodeOptions = ['text' => '123456789'];
$barcode = Barcode::factory('codabar', 'image', $barcodeOptions);
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
$barcodeOptions = ['text' => $this->form->getData()['barcode-object-text']];
$barcode = Barcode::factory($this->form->getData()['barcode-object-select'], 'image', $barcodeOptions);
}
}
imagegif($barcode->draw(), './data/barcode.gif');
return new ViewModel(['form' => $this->form]);
}
示例13: 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]);
}
示例14: indexAction
public function indexAction()
{
if ($this->getRequest()->isPost()) {
$this->installForm->setData(array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()));
if ($this->installForm->isValid()) {
$data = $this->installForm->getData();
if ($data['plugin']['error'] === 0) {
$this->pluginManager->installFile($data['plugin']['tmp_name']);
} else {
$this->pluginManager->installExternal($data['location']);
}
$this->flashMessenger()->addSuccessMessage('The plugin has been installed.');
return $this->redirect()->toRoute('admin/system/plugins');
}
}
return new ViewModel(['plugins' => $this->pluginManager->getPlugins(), 'installForm' => $this->installForm]);
}
示例15: 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]);
}