2

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.

  • 1
    Did you run php bin/magento setup:upgrade check you module in the list as well as cache:clean. – Krishna ijjada Oct 26 '16 at 4:24
  • 1
    i check this code there is not problem in that i think you missed the php bin/magento setup:upgrade of install the module – Qaisar Satti Oct 26 '16 at 5:15
2

Sometimes it fixes the issue after running the following command.

php bin/magento setup:di:compile
0

Please Check with your Vendorname and the Modulename whether it is mentioned properly.Because I had the same issue due to misspelled modulename. But there is no issue on your coding.

0

When Create custom module than first u run command Below step by step

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

Than run in url baseurl/helloworld/index/display

0

You must run the reindex command.

follow these steps

  1. php bin/magento setup:upgrade --keep-generated
  2. php bin/magento indexer:reindex

Note: --keep-generated argument is passed to keep generated static data. Otherwise you have to run setup:static-content:deploy command to regenerate all the static data.

Hope this will help.

0

This may be quite late response. Anyway hope this helps someone else to solve the issue.

In your routes.xml change the below line to have the same value as id and frontname

Before :

<route id="mageplaza" frontName="helloworld">

After :

<route id="helloworld" frontName="helloworld">

Clear cache and try again loading the page

NOTE : If you have different values for route id and frontname the routing will not work properly. Of course it would redirect you up to the controller function (if you echo something and exit from the controller the page would show the echoed wordings), but it would not load the relevant Block there. Obviously, the phtml file will not load.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.