當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。