我一直在尝试在 Magento2 中设置一个基本模块,尽管做了所有理想的更改,它仍然会抛出 404。下面是与模块相关的代码。我的供应商名称是Chirag,模块名称是HelloWorld。
/var/www/html/magento2/app/code/Chirag/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Chirag_HelloWorld" schema_version="0.0.1" setup_version="0.0.1">
</module>
</config>
/var/www/html/magento2/app/code/Chirag/HelloWorld/etc/frontend/route.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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="Chirag_HelloWorld" />
</route>
</router>
</config>
/var/www/html/magento2/app/code/Chirag/HelloWorld/Controller/Index/Index.php
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Chirag\HelloWorld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
/**
*
*
* @return void
*/
public function execute()
{
protected $resultPageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
)
{
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
return $this->resultPageFactory->create();
}
}
}
/var/www/html/magento2/app/code/Chirag/HelloWorld/Block/HelloWorld.php
<?php
namespace Chirag\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{
}
/var/www/html/magento2/app/code/Chirag/HelloWorld/view/frontend/layout/helloworld_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">
<body>
<referenceContainer name="content">
<block class="Chirag\HelloWorld\Block\HelloWorld" name="helloworld" template="helloworld.phtml" />
</referenceContainer>
</body>
</page>
/var/www/html/magento2/app/code/Chirag/HelloWorld/view/frontend/templates/helloworld.phtml
<h1> test hello to Magento 2 !! </h1>
任何形式的帮助将非常感激。