I have created a simple custom module in Magento 2. But its not working. Could anyone please suggest me where I went wrong?
My Code is
app/etc/config.xml
'Sparx_Helloworld' => 1,
app/code/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>
app/code/Sparx/Helloworld/Controller/Index/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();
}
}
app/code/Sparx/Helloworld/Block/Helloworld.php
<?php
namespace Sparx\Helloworld\Block;
class Helloworld extends \Magento\Framework\View\Element\Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
}
app/code/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>
app/code/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>
app/code/Sparx/Helloworld/view/frontend/templates/helloworld.phtml
<?php echo 'Successful! This is a simple helloworld module in Magento 2'; ?>
I'm not sure what is wrong. Please do the needful.
Thanks