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


PHP RawFactory::create方法代码示例

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


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

示例1: execute

 /**
  * Delete file from media storage
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     try {
         if (!$this->getRequest()->isPost()) {
             throw new \Exception('Wrong request.');
         }
         $files = $this->getRequest()->getParam('files');
         /** @var $helper \Magento\Cms\Helper\Wysiwyg\Images */
         $helper = $this->_objectManager->get('Magento\\Cms\\Helper\\Wysiwyg\\Images');
         $path = $this->getStorage()->getSession()->getCurrentPath();
         foreach ($files as $file) {
             $file = $helper->idDecode($file);
             /** @var \Magento\Framework\Filesystem $filesystem */
             $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem');
             $dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
             $filePath = $path . '/' . $file;
             if ($dir->isFile($dir->getRelativePath($filePath))) {
                 $this->getStorage()->deleteFile($filePath);
             }
         }
         return $this->resultRawFactory->create();
     } catch (\Exception $e) {
         $result = ['error' => true, 'message' => $e->getMessage()];
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setData($result);
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:33,代码来源:DeleteFiles.php

示例2: execute

 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     try {
         $uploader = $this->_objectManager->create('Magento\\MediaStorage\\Model\\File\\Uploader', ['fileId' => 'image']);
         $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
         /** @var \Magento\Framework\Image\Adapter\AdapterInterface $imageAdapter */
         $imageAdapter = $this->_objectManager->get('Magento\\Framework\\Image\\AdapterFactory')->create();
         $uploader->addValidateCallback('catalog_product_image', $imageAdapter, 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         /** @var \Magento\Framework\Filesystem\Directory\Read $mediaDirectory */
         $mediaDirectory = $this->_objectManager->get('Magento\\Framework\\Filesystem')->getDirectoryRead(DirectoryList::MEDIA);
         $config = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Media\\Config');
         $result = $uploader->save($mediaDirectory->getAbsolutePath($config->getBaseTmpMediaPath()));
         $this->_eventManager->dispatch('catalog_product_gallery_upload_image_after', ['result' => $result, 'action' => $this]);
         unset($result['tmp_name']);
         unset($result['path']);
         $result['url'] = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Media\\Config')->getTmpMediaUrl($result['file']);
         $result['file'] = $result['file'] . '.tmp';
     } catch (\Exception $e) {
         $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
     }
     /** @var \Magento\Framework\Controller\Result\Raw $response */
     $response = $this->resultRawFactory->create();
     $response->setHeader('Content-type', 'text/plain');
     $response->setContents(json_encode($result));
     return $response;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:31,代码来源:Upload.php

示例3: executeInternal

 /**
  * Update items qty action
  *
  * @return \Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     try {
         $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
         $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
         $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
         $this->creditmemoLoader->load();
         $resultPage = $this->resultPageFactory->create();
         $response = $resultPage->getLayout()->getBlock('order_items')->toHtml();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response = ['error' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['error' => true, 'message' => __('We can\'t update the item\'s quantity right now.')];
     }
     if (is_array($response)) {
         $resultJson = $this->resultJsonFactory->create();
         $resultJson->setData($response);
         return $resultJson;
     } else {
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setContents($response);
         return $resultRaw;
     }
 }
开发者ID:nblair,项目名称:magescotch,代码行数:30,代码来源:UpdateQty.php

示例4: execute

 /**
  * Forward request for a graph image to the web-service
  *
  * This is done in order to include the image to a HTTPS-page regardless of web-service settings
  *
  * @return  \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $error = __('invalid request');
     $httpCode = 400;
     $gaData = $this->_request->getParam('ga');
     $gaHash = $this->_request->getParam('h');
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     if ($gaData && $gaHash) {
         /** @var $helper \Magento\Backend\Helper\Dashboard\Data */
         $helper = $this->_objectManager->get('Magento\\Backend\\Helper\\Dashboard\\Data');
         $newHash = $helper->getChartDataHash($gaData);
         if ($newHash == $gaHash) {
             $params = json_decode(base64_decode(urldecode($gaData)), true);
             if ($params) {
                 try {
                     /** @var $httpClient \Magento\Framework\HTTP\ZendClient */
                     $httpClient = $this->_objectManager->create('Magento\\Framework\\HTTP\\ZendClient');
                     $response = $httpClient->setUri(\Magento\Backend\Block\Dashboard\Graph::API_URL)->setParameterGet($params)->setConfig(['timeout' => 5])->request('GET');
                     $headers = $response->getHeaders();
                     $resultRaw->setHeader('Content-type', $headers['Content-type'])->setContents($response->getBody());
                     return $resultRaw;
                 } catch (\Exception $e) {
                     $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
                     $error = __('see error log for details');
                     $httpCode = 503;
                 }
             }
         }
     }
     $resultRaw->setHeader('Content-Type', 'text/plain; charset=UTF-8')->setHttpResponseCode($httpCode)->setContents(__('Service unavailable: %1', $error));
     return $resultRaw;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:40,代码来源:Tunnel.php

示例5: execute

 /**
  * Login registered users and initiate a session.
  *
  * Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"}
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $credentials = null;
     $httpBadRequestCode = 400;
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     try {
         $credentials = $this->helper->jsonDecode($this->getRequest()->getContent());
     } catch (\Exception $e) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     $response = ['errors' => false, 'message' => __('Login successful.')];
     try {
         $customer = $this->customerAccountManagement->authenticate($credentials['username'], $credentials['password']);
         $this->customerSession->setCustomerDataAsLoggedIn($customer);
         $this->customerSession->regenerateId();
     } catch (EmailNotConfirmedException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (InvalidEmailOrPasswordException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['errors' => true, 'message' => __('Something went wrong while validating the login and password.')];
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($response);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:37,代码来源:Login.php

示例6: execute

 /**
  * Check whether vat is valid
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $result = $this->_validate();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents((int) $result->getIsValid());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Validate.php

示例7: execute

 /**
  * Save fieldset state through AJAX
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     if ($this->getRequest()->getParam('isAjax') && $this->getRequest()->getParam('container') != '' && $this->getRequest()->getParam('value') != '') {
         $configState = [$this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')];
         $this->_saveState($configState);
         /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
         $resultRaw = $this->resultRawFactory->create();
         return $resultRaw->setContents('success');
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:State.php

示例8: execute

 /**
  * WYSIWYG editor action for ajax request
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $elementId = $this->getRequest()->getParam('element_id', md5(microtime()));
     $storeId = $this->getRequest()->getParam('store_id', 0);
     $storeMediaUrl = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
     $content = $this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Helper\\Form\\Wysiwyg\\Content', '', ['data' => ['editor_element_id' => $elementId, 'store_id' => $storeId, 'store_media_url' => $storeMediaUrl]]);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($content->toHtml());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Wysiwyg.php

示例9: execute

 /**
  * Get specified tab grid
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Products'));
     $this->productBuilder->build($this->getRequest());
     $block = $this->getRequest()->getParam('gridOnlyBlock');
     $blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block)));
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\' . $blockClassSuffix)->toHtml());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:GridOnly.php

示例10: execute

 /**
  * Chooser Source action
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $uniqId = $this->getRequest()->getParam('uniq_id');
     /** @var \Magento\Framework\View\Layout $layout */
     $layout = $this->layoutFactory->create();
     $pagesGrid = $layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Page\\Widget\\Chooser', '', ['data' => ['id' => $uniqId]]);
     $html = $pagesGrid->toHtml();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($html);
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:16,代码来源:Chooser.php

示例11: execute

 /**
  * Show item update result from loadBlockAction
  * to prevent popup alert with resend data question
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     $session = $this->_objectManager->get('Magento\\Backend\\Model\\Session');
     if ($session->hasUpdateResult() && is_scalar($session->getUpdateResult())) {
         $resultRaw->setContents($session->getUpdateResult());
     }
     $session->unsUpdateResult();
     return $resultRaw;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:ShowUpdateResult.php

示例12: execute

 /**
  * Grid Action
  * Display list of products related to current category
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $category = $this->_initCategory(true);
     if (!$category) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tab\\Product', 'category.product.grid')->toHtml());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:Grid.php

示例13: execute

 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $output = '';
     $blockTab = $this->getRequest()->getParam('block');
     $blockClassSuffix = str_replace(' ', '\\', ucwords(str_replace('_', ' ', $blockTab)));
     if (in_array($blockTab, ['tab_orders', 'tab_amounts', 'totals'])) {
         $output = $this->layoutFactory->create()->createBlock('Magento\\Backend\\Block\\Dashboard\\' . $blockClassSuffix)->toHtml();
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($output);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:AjaxBlock.php

示例14: execute

 /**
  * Delete folder action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     try {
         $path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
         $this->getStorage()->deleteDirectory($path);
         return $this->resultRawFactory->create();
     } catch (\Exception $e) {
         $result = ['error' => true, 'message' => $e->getMessage()];
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setData($result);
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:DeleteFolder.php

示例15: execute

 /**
  * Fire when select image
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $helper = $this->_objectManager->get('Magento\\Cms\\Helper\\Wysiwyg\\Images');
     $storeId = $this->getRequest()->getParam('store');
     $filename = $this->getRequest()->getParam('filename');
     $filename = $helper->idDecode($filename);
     $asIs = $this->getRequest()->getParam('as_is');
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Data')->setStoreId($storeId);
     $helper->setStoreId($storeId);
     $image = $helper->getImageHtmlDeclaration($filename, $asIs);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($image);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:OnInsert.php


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