2

Magento 2 で簡単なカスタム モジュールを作成しましたが、機能しません。誰かが私が間違っていた場所を教えてもらえますか?

私のコードは

アプリ/etc/config.xml

'Sparx_Helloworld' => 1,

アプリ/コード/Sparx/Helloworld/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="Sparx_Helloworld" schema_version="0.0.1" active="true">
    </module>
</config>

アプリ/コード/Sparx/Helloworld/コントローラー/インデックス/Index.php

<?php
namespace Sparx\Helloworld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
    }
}

アプリ/コード/Sparx/Helloworld/ブロック/Helloworld.php

<?php
namespace Sparx\Helloworld\Block;
class Helloworld extends \Magento\Framework\View\Element\Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
}

アプリ/コード/Sparx/Helloworld/etc/frontend/routes.xml

<?xml version="1.0"?>
<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="helloworld" frontName="helloworld">
            <module name="Sparx_Helloworld" />
        </route>
    </router>
</config>

アプリ/コード/Sparx/Helloworld/etc/view/frontend/layout/helloworld_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Welcome to Magento World</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block name="helloworld" template="helloworld.phtml">
            </block>
        </referenceContainer>
    </body>
</page>

アプリ/コード/Sparx/Helloworld/view/frontend/templates/helloworld.phtml

<?php echo 'Successful! This is a simple helloworld module in Magento 2'; ?>

エラーを下回っています ここに画像の説明を入力

何が悪いのかわかりません。必要なことをしてください。

ありがとう

4

1 に答える 1

3

module.xml は次のようになります。

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Sparx_Helloworld" setup_version="0.0.1">
    </module>
</config>

最新バージョンの magento 2 (1.0.0-beta5) で作業している場合は、このファイルもSparx/Helloworld

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Sparx_Helloworld',
    __DIR__
);

ファイルphp bin/magento setup:upgradeに追加する'Sparx_Helloworld' => 1,のではなく、コマンドラインで実行する必要がある場合がありますconfig.php

于 2015-10-30T14:03:10.587 に答える