Trying to follow this https://www.mageplaza.com/magento-2-module-development/ to create a module, but nothing is working for me.
I am using Magento with xampp.
My root folder name is Magento2
path: C:\xampp\htdocs\Magento2\app\code\Mageplaza
created: HelloWorld folder
C:\xampp\htdocs\Magento2\app\code\Mageplaza\HelloWorld
- Controller folder
- etc folder
- registration.php
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mageplaza_HelloWorld',
__DIR__
);
Inside etc folder:
- frontend folder
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="Mageplaza_HelloWorld" setup_version="2.0.0" />
</config>
Inside frontend folder
routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="mageplaza" frontName="helloworld">
<module name="Mageplaza_HelloWorld" />
</route>
</router>
</config>
Inside Controller folder:
- Index folder
Inside Index folder:
Display.php
<?php
namespace Mageplaza\HelloWorld\Controller\Index;
class Display extends \Magento\Framework\App\Action\Action
{
public function __construct(\Magento\Framework\App\Action\Context $context)
{
return parent::__construct($context);
}
public function execute()
{
echo 'Hello World';
exit;
}
}
url: http://localhost/Magento2/helloworld/index/display
result: 404
Any idea where I am going wrong, just started learning magneto2.
Best Answer
Sometimes it fixes the issue after running the following command.