Magento 2 adminhtml - 自定义块提供空白页面

Magento 2 adminhtml - custom block gives blank page

我正在创建一个后端 magento 2 模块,当我在布局文件中指定一个自定义块时,它将显示一个空白页面,并将其添加到 system.log

[2016-10-19 07:35:35] main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_32fdcd7fcff058e6f791ea5b6050bd6b5 and handles default, widget_selectwidget_index: Please correct the XML data and try again. [] [] [2016-10-19 07:35:35] main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_3a2e4822a98337283e39f7b60acf85ec9 and handles empty: Please correct the XML data and try again. [] [] [2016-10-19 07:35:35] main.CRITICAL: Broken reference: the 'logo' element cannot be added as child to 'header', because the latter doesn't exist [] [] [2016-10-19 07:35:35] main.CRITICAL: Broken reference: the 'global.search' element cannot be added as child to 'header', because the latter doesn't exist [] [] [2016-10-19 07:35:35] main.CRITICAL: Broken reference: the 'user' element cannot be added as child to 'header', because the latter doesn't exist [] []

.....等等等等....

[2016-10-19 07:35:35] main.CRITICAL: Broken reference: the 'header.inner.right' tries to reorder itself towards 'header.inner.left', but their parents are different: 'header' and '' respectively. [] [] [2016-10-19 07:35:35] main.CRITICAL: Broken reference: the 'global.search' tries to reorder itself towards 'notification.messages', but their parents are different: 'header.inner.right' and '' respectively. [] [] [2016-10-19 07:35:35] main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_36f1b068ec7ccf4878f9284dd1137afd1 and handles catalog_product_prices: Please correct the XML data and try again. [] []

如果我将块 class 指定为 class="Magento\Backend\Block\Template" 那么它将显示具有正确模板的页面,这让我认为模板没有问题或模块的其余部分。

这是区块 (app/code/Vendor/Widget/Block/Adminhtml/SelectWidgetBlock.php) :

namespace Vendor\Widget\Block\Adminhtml;
use Magento\Backend\Block\Template;

class SelectWidgetBlock extends Template
{
    public function __construct(Template\Context $context, array $data = []) 
    {
        parent::__construct($context, $data);
    }

    public function greet()
    {
        return 'Hello world';
    }
}

这是布局文件(app/code/Vendor/Widget/view/adminhtml/layout/widget_selectwidget_index.xml):

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="empty">
<head>
    <title>
        Widget
    </title>
</head>
<body>
    <referenceContainer name="content">
        <block class="Vendor\Widget\Block\Adminhtml\SelectWidgetBlock" name="vendor_widget.select" template="Vendor_Widget::selectwidget.phtml"/>
    </referenceContainer>
</body>

现在 phtml (app/code/Vendor/Widget/view/adminhtml/templates/selectwidget.phtml) :

<p>Here is the phtml file</p>

<?php echo $this->greet() ?>

这里是控制器以防万一(app/code/Vendor/Widget/Controller/Adminhtml/SelectWidget/Index.php) :

namespace Vendor\Widget\Controller\Adminhtml\SelectWidget;

class Index extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {
        return  $resultPage = $this->resultPageFactory->create();
    }
}

如果你有什么想法,请!

我通过从布局文件中删除 layout="empty" 解决了我的问题。