Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento2 自定义模块中的空白页(Magento 2 Beta商户版本1.0.0)_Magento2 - Fatal编程技术网

Magento2 自定义模块中的空白页(Magento 2 Beta商户版本1.0.0)

Magento2 自定义模块中的空白页(Magento 2 Beta商户版本1.0.0),magento2,Magento2,我使用的是Magento 2 beta Merchant 1.0.0版 我正在尝试创建一个新的自定义模块。自定义模块工作,但显示空白页 如何使我的模块使用主模板 这就是我到目前为止所做的: 文件夹结构: Magento2 文件内容: 1) Composer.json: { "name": "vendor-software/hellow-sample-module", "description": "module based on composer!", "require": { "mag

我使用的是Magento 2 beta Merchant 1.0.0版

我正在尝试创建一个新的自定义模块。自定义模块工作,但显示空白页

如何使我的模块使用主模板

这就是我到目前为止所做的:

文件夹结构: Magento2

文件内容: 1) Composer.json:

{
"name": "vendor-software/hellow-sample-module",
"description": "module based on composer!",
"require": {
    "magento/magento-composer-installer": "*",
    "magento/product-community-edition": "2.0.0"
    },
"type": "magento2-module",
"version": "0.1.0",
"extra": {
    "map": [
        [
            "*",
            "Vendor/Hellow"
        ]
    ]
},
"authors": [
    {
        "name": "Vendor",
        "homepage": "https://www.vendor.com/",
        "role": "Developer"
    }
]
}
2) /Vendor/Hellow/Block/Hellow.php:

<?php
namespace Vendor\hellow\Block;

use Magento\Framework\View\Element\Template;

class Hellow extends Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }   

    public function __construct(Template\Context $context, array $data = [])
    {
        parent::__construct($context, $data);
        $this->_isScopePrivate = true;
    }
}
4) /Vendor/Hellow/etc/module.xml:

<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
        <module name="Vendor_Hellow" setup_version="2.0.0">
        </module>
    </config>

5) /Vendor/Hellow/etc/frontend/routes.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
        <router id="standard">
            <route id="hellow" frontName="hellow">
                <module name="Vendor_Hellow" />
            </route>
        </router>
    </config>

6) /Vendor/Hellow/view/frontend/layout/Hellow\u index\u index.xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
        <head>
            <title>Hello World</title>
        </head>
        <body>
            <referenceContainer name="content">
                <block class="Vendor\Hellow\Block\Hellow" name="hellow" template="hellow.phtml" />
            </referenceContainer>
        </body>
    </page>

你好,世界
7) /Vendor/Hellow/view/frontend/templates/Hellow.phtml:

<h1>Hello World!</h1>
你好,世界!
当我访问地址localhost/magento2/hellow/index/时,结果是一个空白页。但它应该在Magento主页结构中显示一个空白页面,显示标题、菜单、内容等

我做错了什么


谢谢

看起来您在布局句柄的名称上有一个错误。它应该是hellow_index_index.xml,您有hellow_index.index.xml。还要检查您是否遗漏了Vendor/Hellow/Controller/Index/Index.php中的名称空间。

为了开发Hello World模块,您可以参考我共享的git。。如果发现任何困难,请告诉我。

只需在布局xml的页面节点中添加layout=“2列左”。这将解决您的空白页问题

嗨,瓦莱里。。谢谢,你说什么?因为,我在index.php控制器的头中声明了我的命名空间。关于布局文件的名称,根据Magento wiki:你应该使用(下划线)而不是(点)@DMiller,我的意思是在你的帖子中找到这样的字符串:6)/Vendor/Hellow/view/frontend/layout/Hellow\u index.index.xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
        <head>
            <title>Hello World</title>
        </head>
        <body>
            <referenceContainer name="content">
                <block class="Vendor\Hellow\Block\Hellow" name="hellow" template="hellow.phtml" />
            </referenceContainer>
        </body>
    </page>
<h1>Hello World!</h1>