本文整理汇总了PHP中Magento\Framework\App\ViewInterface::renderLayout方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewInterface::renderLayout方法的具体用法?PHP ViewInterface::renderLayout怎么用?PHP ViewInterface::renderLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\ViewInterface
的用法示例。
在下文中一共展示了ViewInterface::renderLayout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareAndRender
/**
* Prepares product view page - inits layout and all needed stuff
*
* $params can have all values as $params in \Magento\Catalog\Helper\Product - initProduct().
* Plus following keys:
* - 'buy_request' - \Magento\Framework\Object holding buyRequest to configure product
* - 'specify_options' - boolean, whether to show 'Specify options' message
* - 'configure_mode' - boolean, whether we're in Configure-mode to edit product configuration
*
* @param int $productId
* @param \Magento\Framework\App\Action\Action $controller
* @param null|\Magento\Framework\Object $params
*
* @return \Magento\Catalog\Helper\Product\View
* @throws \Magento\Framework\Model\Exception
*/
public function prepareAndRender($productId, $controller, $params = null)
{
// Prepare data
$productHelper = $this->_catalogProduct;
if (!$params) {
$params = new \Magento\Framework\Object();
}
// Standard algorithm to prepare and render product view page
$product = $productHelper->initProduct($productId, $controller, $params);
if (!$product) {
throw new \Magento\Framework\Model\Exception(__('Product is not loaded'), $this->ERR_NO_PRODUCT_LOADED);
}
$buyRequest = $params->getBuyRequest();
if ($buyRequest) {
$productHelper->prepareProductOptions($product, $buyRequest);
}
if ($params->hasConfigureMode()) {
$product->setConfigureMode($params->getConfigureMode());
}
$this->_eventManager->dispatch('catalog_controller_product_view', array('product' => $product));
$this->_catalogSession->setLastViewedProductId($product->getId());
$this->initProductLayout($product, $controller, $params);
if ($controller instanceof \Magento\Catalog\Controller\Product\View\ViewInterface) {
$this->_view->getLayout()->initMessages($this->messageGroups);
} else {
throw new \Magento\Framework\Model\Exception(__('Bad controller interface for showing product'), $this->ERR_BAD_CONTROLLER_INTERFACE);
}
$this->_view->renderLayout();
return $this;
}
示例2: _renderPage
/**
* Renders CMS page
*
* @param Action $action
* @param int $pageId
* @param bool $renderLayout
* @return bool
*/
protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
{
if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
$delimiterPosition = strrpos($pageId, '|');
if ($delimiterPosition) {
$pageId = substr($pageId, 0, $delimiterPosition);
}
$this->_page->setStoreId($this->_storeManager->getStore()->getId());
if (!$this->_page->load($pageId)) {
return false;
}
}
if (!$this->_page->getId()) {
return false;
}
$inRange = $this->_localeDate->isScopeDateInInterval(null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo());
if ($this->_page->getCustomTheme()) {
if ($inRange) {
$this->_design->setDesignTheme($this->_page->getCustomTheme());
}
}
if ($this->_page->getPageLayout()) {
if ($this->_page->getCustomPageLayout() && $this->_page->getCustomPageLayout() != 'empty' && $inRange) {
$handle = $this->_page->getCustomPageLayout();
} else {
$handle = $this->_page->getPageLayout();
}
$this->pageConfig->setPageLayout($handle);
}
$this->_view->getPage()->initLayout();
$this->_view->getLayout()->getUpdate()->addHandle('cms_page_view');
$this->_view->addPageLayoutHandles(array('id' => $this->_page->getIdentifier()));
$this->_eventManager->dispatch('cms_page_render', array('page' => $this->_page, 'controller_action' => $action));
$this->_view->loadLayoutUpdates();
if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
$layoutUpdate = $this->_page->getCustomLayoutUpdateXml();
} else {
$layoutUpdate = $this->_page->getLayoutUpdateXml();
}
if (!empty($layoutUpdate)) {
$this->_view->getLayout()->getUpdate()->addUpdate($layoutUpdate);
}
$this->_view->generateLayoutXml()->generateLayoutBlocks();
$contentHeadingBlock = $this->_view->getLayout()->getBlock('page_content_heading');
if ($contentHeadingBlock) {
$contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading());
$contentHeadingBlock->setContentHeading($contentHeading);
}
/* @TODO: Move catalog and checkout storage types to appropriate modules */
$messageBlock = $this->_view->getLayout()->getMessagesBlock();
$messageBlock->addStorageType($this->messageManager->getDefaultGroup());
$messageBlock->addMessages($this->messageManager->getMessages(true));
if ($renderLayout) {
$this->_view->renderLayout();
}
return true;
}
示例3: renderConfigureResult
/**
* Prepares and render result of composite product configuration request
*
* The $configureResult variable holds either:
* - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer_id'
* - 'error' = true, and 'message' to show
*
* @param \Magento\Framework\Object $configureResult
* @return void
*/
public function renderConfigureResult(\Magento\Framework\Object $configureResult)
{
try {
if (!$configureResult->getOk()) {
throw new \Magento\Framework\Model\Exception($configureResult->getMessage());
}
$currentStoreId = (int) $configureResult->getCurrentStoreId();
if (!$currentStoreId) {
$currentStoreId = $this->_storeManager->getStore()->getId();
}
$product = $this->_productFactory->create()->setStoreId($currentStoreId)->load($configureResult->getProductId());
if (!$product->getId()) {
throw new \Magento\Framework\Model\Exception(__('The product is not loaded.'));
}
$this->_coreRegistry->register('current_product', $product);
$this->_coreRegistry->register('product', $product);
// Register customer we're working with
$customerId = (int) $configureResult->getCurrentCustomerId();
// TODO: Remove the customer model from the registry once all readers are refactored
$customerModel = $this->_converter->loadCustomerModel($customerId);
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER, $customerModel);
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
// Prepare buy request values
$buyRequest = $configureResult->getBuyRequest();
if ($buyRequest) {
$this->_catalogProduct->prepareProductOptions($product, $buyRequest);
}
$isOk = true;
$productType = $product->getTypeId();
} catch (\Exception $e) {
$isOk = false;
$productType = null;
$this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
}
$this->_initConfigureResultLayout($isOk, $productType);
$this->_view->renderLayout();
}