4

I created a simple module, it is registered and shows up in
Stores -> Configuration -> Advanced -> Advanced,
then I created routes.xml and Display.php.

app\code\Jurgis\Twilio_settings\etc\frontend\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="Jurgis" frontName="Twilio_settings">
            <module name="Jurgis_Twilio_settings" />
        </route>
    </router>
</config>

app\code\Jurgis\Twilio_settings\Controller\Index\Display.php

<?php
namespace Jurgis\Twilio_settings\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;
  }
}

But when I go to: "http://localhost/magento2/Twilio_settings/index/display"
I get the 404 not found error.
What have I done wrong?

5

1 Answer 1

6

You need some little modification.

Jurgis/Twilio/registration.php


\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Jurgis_Twilio',
    __DIR__
);

Jurgis/Twilio/etc/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="Jurgis_Twilio" setup_version="2.0.0">
    </module>
</config>

Jurgis/Twilio/etc/frontend/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="Jurgis" frontName="Twilio_settings">
            <module name="Jurgis_Twilio" />
        </route>
    </router>
</config>

Jurgis/Twilio/Controller/Index/Display.php


namespace Jurgis\Twilio\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;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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