當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Http\FileFactory類代碼示例

本文整理匯總了PHP中Magento\Framework\App\Response\Http\FileFactory的典型用法代碼示例。如果您正苦於以下問題:PHP FileFactory類的具體用法?PHP FileFactory怎麽用?PHP FileFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FileFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Export shipment grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $resultPage = $this->resultPageFactory->create();
     $fileName = 'authors.csv';
     /** @var \Sample\News\Block\Adminhtml\Author\Grid $grid */
     $grid = $resultPage->getLayout()->getChildBlock('sample_news.author.grid', 'grid.export');
     return $this->fileFactory->create($fileName, $grid->getCsvFile(), DirectoryList::VAR_DIR);
 }
開發者ID:nhc,項目名稱:Magento2SampleModule,代碼行數:13,代碼來源:ExportCsv.php

示例2: execute

 /**
  * Export shipment grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout(false);
     $fileName = 'shipments.csv';
     $grid = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $grid->getCsvFile(), \Magento\Framework\App\Filesystem::VAR_DIR);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:12,代碼來源:ExportCsv.php

示例3: execute

 /**
  * Export invoice grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $fileName = 'invoices.csv';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $this->resultLayoutFactory->create()->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:12,代碼來源:ExportCsv.php

示例4: executeInternal

 /**
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
  */
 public function executeInternal()
 {
     /** @see \Magento\Sales\Controller\Adminhtml\Order\Invoice */
     $creditmemoId = $this->getRequest()->getParam('creditmemo_id');
     if ($creditmemoId) {
         $creditmemo = $this->creditmemoRepository->get($creditmemoId);
         if ($creditmemo) {
             $pdf = $this->_objectManager->create(
                 'Magento\Sales\Model\Order\Pdf\Creditmemo'
             )->getPdf(
                 [$creditmemo]
             );
             $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s');
             return $this->_fileFactory->create(
                 'creditmemo' . $date . '.pdf',
                 $pdf->render(),
                 DirectoryList::VAR_DIR,
                 'application/pdf'
             );
         }
     } else {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
開發者ID:nblair,項目名稱:magescotch,代碼行數:29,代碼來源:PrintAction.php

示例5: executeInternal

    /**
     * Create pdf document with information about packages
     *
     * @return ResponseInterface|void
     */
    public function executeInternal()
    {
        $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
        $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
        $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
        $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
        $shipment = $this->shipmentLoader->load();

        if ($shipment) {
            /** @var \Zend_Pdf $pdf */
            $pdf = $this->_objectManager->create('Magento\Shipping\Model\Order\Pdf\Packaging')->getPdf($shipment);
            return $this->_fileFactory->create(
                'packingslip' . $this->_objectManager->get(
                    'Magento\Framework\Stdlib\DateTime\DateTime'
                )->date(
                    'Y-m-d_H-i-s'
                ) . '.pdf',
                $pdf->render(),
                DirectoryList::VAR_DIR,
                'application/pdf'
            );
        } else {
            $this->_forward('noroute');
        }
    }
開發者ID:nblair,項目名稱:magescotch,代碼行數:30,代碼來源:PrintPackage.php

示例6: execute

 /**
  * Custom options download action
  *
  * @return \Magento\Framework\Controller\Result\Forward
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function execute()
 {
     $option = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->load($this->getRequest()->getParam('id'));
     /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
     $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
     if (!$option->getId()) {
         $resultForward->forward('noroute');
         return $resultForward;
     }
     $optionId = null;
     if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
         $optionId = str_replace(\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode());
         if ((int) $optionId != $optionId) {
             $resultForward->forward('noroute');
             return $resultForward;
         }
     }
     $productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId);
     if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') {
         $resultForward->forward('noroute');
         return $resultForward;
     }
     try {
         $info = unserialize($option->getValue());
         $secretKey = $this->getRequest()->getParam('key');
         if ($secretKey == $info['secret_key']) {
             $this->_fileResponseFactory->create($info['title'], ['value' => $info['quote_path'], 'type' => 'filename'], DirectoryList::ROOT);
         }
     } catch (\Exception $e) {
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:40,代碼來源:DownloadCustomOption.php

示例7: execute

 /**
  * Export invoice grid to Excel XML format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout();
     $fileName = 'invoices.xml';
     $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getExcelFile($fileName), \Magento\Framework\App\Filesystem::VAR_DIR);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:12,代碼來源:ExportExcel.php

示例8: execute

 /**
  * Export search report to Excel XML format
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
     $content = $resultLayout->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export');
     return $this->fileFactory->create('search.xml', $content->getExcelFile(), DirectoryList::VAR_DIR);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:12,代碼來源:ExportSearchExcel.php

示例9: executeInternal

 /**
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
  */
 public function executeInternal()
 {
     $shipmentId = $this->getRequest()->getParam('shipment_id');
     if ($shipmentId) {
         $shipment = $this->_objectManager->create('Magento\Sales\Model\Order\Shipment')->load($shipmentId);
         if ($shipment) {
             $pdf = $this->_objectManager->create(
                 'Magento\Sales\Model\Order\Pdf\Shipment'
             )->getPdf(
                 [$shipment]
             );
             $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s');
             return $this->_fileFactory->create(
                 'packingslip' . $date . '.pdf',
                 $pdf->render(),
                 DirectoryList::VAR_DIR,
                 'application/pdf'
             );
         }
     } else {
         /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
         $resultForward = $this->resultForwardFactory->create();
         return $resultForward->forward('noroute');
     }
 }
開發者ID:nblair,項目名稱:magescotch,代碼行數:28,代碼來源:PrintAction.php

示例10: execute

 /**
  * Custom options download action
  *
  * @return void
  */
 public function execute()
 {
     $option = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->load($this->getRequest()->getParam('id'));
     if (!$option->getId()) {
         return $this->_forward('noroute');
     }
     $optionId = null;
     if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
         $optionId = str_replace(\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode());
         if ((int) $optionId != $optionId) {
             return $this->_forward('noroute');
         }
     }
     $productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId);
     if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') {
         return $this->_forward('noroute');
     }
     try {
         $info = unserialize($option->getValue());
         $filePath = $this->_objectManager->get('Magento\\Framework\\App\\Filesystem')->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . $info['quote_path'];
         $secretKey = $this->getRequest()->getParam('key');
         if ($secretKey == $info['secret_key']) {
             $this->_fileResponseFactory->create($info['title'], array('value' => $filePath, 'type' => 'filename'), \Magento\Framework\App\Filesystem::ROOT_DIR);
         }
     } catch (\Exception $e) {
         $this->_forward('noroute');
     }
     exit(0);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:34,代碼來源:DownloadCustomOption.php

示例11: massAction

 /**
  * Print invoices for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     $flag = false;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $invoices = $order->getInvoiceCollection();
         if ($invoices->getSize() > 0) {
             $flag = true;
             if (!isset($pdf)) {
                 $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
             } else {
                 $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
                 $pdf->pages = array_merge($pdf->pages, $pages->pages);
             }
         }
     }
     if ($flag) {
         $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
         return $this->fileFactory->create('invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     } else {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         $resultRedirect->setPath('sales/*/');
         return $resultRedirect;
     }
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:32,代碼來源:Pdfinvoices.php

示例12: execute

 /**
  * Print label for one specific shipment
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     try {
         $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
         $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
         $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
         $shipment = $this->shipmentLoader->load();
         $labelContent = $shipment->getShippingLabel();
         if ($labelContent) {
             $pdfContent = null;
             if (stripos($labelContent, '%PDF-') !== false) {
                 $pdfContent = $labelContent;
             } else {
                 $pdf = new \Zend_Pdf();
                 $page = $this->labelGenerator->createPdfPageFromImageString($labelContent);
                 if (!$page) {
                     $this->messageManager->addError(__('We don\'t recognize or support the file extension in this shipment: %1.', $shipment->getIncrementId()));
                 }
                 $pdf->pages[] = $page;
                 $pdfContent = $pdf->render();
             }
             return $this->_fileFactory->create('ShippingLabel(' . $shipment->getIncrementId() . ').pdf', $pdfContent, DirectoryList::VAR_DIR, 'application/pdf');
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError(__('An error occurred while creating shipping label.'));
     }
     $this->_redirect('adminhtml/order_shipment/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:37,代碼來源:PrintLabel.php

示例13: testCreate

 public function testCreate()
 {
     $authStorageMock = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', array('isFirstPageAfterLogin', 'processLogout', 'processLogin'), array(), '', false);
     $this->_authMock->expects($this->once())->method('getAuthStorage')->will($this->returnValue($authStorageMock));
     $authStorageMock->expects($this->once())->method('isFirstPageAfterLogin')->will($this->returnValue(true));
     $this->_sessionMock->expects($this->once())->method('setIsUrlNotice');
     $this->_model->create('fileName', null);
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:8,代碼來源:FileFactoryTest.php

示例14: execute

 /**
  * Export customer grid to CSV format
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout();
     $fileName = 'customers.csv';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $this->_view->getLayout()->getChildBlock('admin.block.customer.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:ExportCsv.php

示例15: execute

 /**
  * Export credit memo grid to Excel XML format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $fileName = 'creditmemos.xml';
     $resultLayout = $this->resultLayoutFactory->create();
     $grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export');
     $excelFile = $grid->getExcelFile($fileName);
     return $this->_fileFactory->create($fileName, $excelFile, DirectoryList::VAR_DIR);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:13,代碼來源:ExportExcel.php


注:本文中的Magento\Framework\App\Response\Http\FileFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。