当前位置: 首页>>代码示例>>PHP>>正文


PHP Generic::setFormData方法代码示例

本文整理汇总了PHP中Magento\Framework\Session\Generic::setFormData方法的典型用法代码示例。如果您正苦于以下问题:PHP Generic::setFormData方法的具体用法?PHP Generic::setFormData怎么用?PHP Generic::setFormData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Session\Generic的用法示例。


在下文中一共展示了Generic::setFormData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Check CAPTCHA on New Testmonial page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'testimonial_new';
     $captcha = $this->_helper->getCaptcha($formId);
     if ($captcha->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
             $this->_testimonialSession->setFormData($controller->getRequest()->getPost());
             $this->messageManager->addError(__('Incorrect CAPTCHA.'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
         }
     }
 }
开发者ID:swissup,项目名称:testimonials,代码行数:21,代码来源:CheckTestimonialFormObserver.php

示例2: dispatch

 /**
  * Dispatch request
  *
  * @param RequestInterface $request
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function dispatch(RequestInterface $request)
 {
     $allowGuest = $this->_objectManager->get('Magento\\Review\\Helper\\Data')->getIsGuestAllowToWrite();
     if (!$request->isDispatched()) {
         return parent::dispatch($request);
     }
     if (!$allowGuest && $request->getActionName() == 'post' && $request->isPost()) {
         if (!$this->_customerSession->isLoggedIn()) {
             $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
             $this->_customerSession->setBeforeAuthUrl($this->_url->getUrl('*/*/*', ['_current' => true]));
             $this->_reviewSession->setFormData($request->getPostValue())->setRedirectUrl($this->_redirect->getRefererUrl());
             $this->getResponse()->setRedirect($this->_objectManager->get('Magento\\Customer\\Model\\Url')->getLoginUrl());
         }
     }
     return parent::dispatch($request);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:22,代码来源:Product.php

示例3: execute

 /**
  * Save user testimonial
  *
  * @return void
  * @throws \Exception
  */
 public function execute()
 {
     $post = $this->getRequest()->getPostValue();
     if (!$post) {
         $this->_redirectReferer();
         return;
     }
     try {
         $error = false;
         if (!\Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
             $error = true;
         }
         if (!\Zend_Validate::is(trim($post['message']), 'NotEmpty')) {
             $error = true;
         }
         if (!\Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
             $error = true;
         }
         if ($error) {
             throw new \Exception();
         }
         $post['store_id'] = $this->_storeManager->getStore()->getId();
         $post['status'] = $this->_configHelper->isAutoApprove() ? TestimonialsModel::STATUS_ENABLED : TestimonialsModel::STATUS_AWAITING_APPROVAL;
         $model = $this->_objectManager->create('Swissup\\Testimonials\\Model\\Data');
         $model->setData($post);
         $imageName = $this->_uploadModel->uploadFileAndGetName('image', $this->_imageModel->getBaseDir(), $post, ['jpg', 'jpeg', 'gif', 'png', 'bmp']);
         $model->setImage($imageName);
         $this->_eventManager->dispatch('testimonials_save_new', ['item' => $model]);
         $model->save();
         $this->messageManager->addSuccess(__($this->_configHelper->getSentMessage()));
         $this->_redirectReferer();
         return;
     } catch (\Exception $e) {
         $this->messageManager->addError(__($e->getMessage()));
         $this->_testimonialSession->setFormData($post)->setRedirectUrl($this->_redirect->getRefererUrl());
         $this->_redirectReferer();
         return;
     }
 }
开发者ID:swissup,项目名称:testimonials,代码行数:45,代码来源:Save.php


注:本文中的Magento\Framework\Session\Generic::setFormData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。