1

I have a module with routers have frontName as "ticket". It working in Magento version 2.0.0-rc. But when i install this module in Magento version 2.0.0-rc2, i request to this routers and browser return "404 Page".

How to fix this routers ?

Thanks for advice.

This is very strange, because my module working normally with Magento 2.0.0-rc.

EDIT

My code in below.

app/code/Demo/Ticket/etc/frontend/routers.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="ticket" frontName="ticket">
            <module name="Demo_Ticket" />
        </route>
    </router>
</config>

app/code/Demo/Ticket/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                        xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framewo rk/Module/etc/module.xsd">
   <module name="Demo_Ticket" setup_version="1.0.0">
      <sequence>
         <module name="Magento_Backend"/>
      </sequence>
   </module>
</config>

app/code/Demo/Ticket/Controller/Index/Index.php

<?php
   namespace Demo\Ticket\Controller\Index;

   class Index extends \Magento\Framework\App\Action\Action
   {
        public function __construct(
           \Magento\Framework\App\Action\Context $context,
        ){
           parent::__construct($context);
        }

       public function execute()
       {
           echo "Event Ticket";
       }
   }

app/code/Demo/Ticket/registration.php

<?php
   /**
    * Copyright © 2015 Magento. All rights reserved.
    * See COPYING.txt for license details.
    */

   \Magento\Framework\Component\ComponentRegistrar::register(
     \Magento\Framework\Component\ComponentRegistrar::MODULE,
      'Demo_Ticket',
       __DIR__
    );
1
  • Can you post the your code to see how you register the new route? Commented Nov 16, 2015 at 9:38

3 Answers 3

2

Please make sure that you have registration.php in your module. See official guide about registering your module in Magento 2. If that does not help, check out this issue (which prevents installation of non-composer modules).

1
  • Yes, i have registration.php in my module, so i can run in Magento 2.0.0 RC
    – LinoPham
    Commented Nov 16, 2015 at 9:50
1

Make sure Your/Module/etc/frontend/routes.xml looks something like this:

<?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="yourmodule" frontName="ticket">
            <module name="Your_Module" />
        </route>
    </router>
</config>

And you have a matching Your/Module/Controller/Index/Index.php file like this:

<?php
namespace Your\Module\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    /**
     * Index action
     *
     * @return $this
     */
    public function execute()
    {
        die('tickets');
    }
}

That should display "tickets" if you navigate to http://www.example.com/ticket, make sure to adjust the Directory names to match your URL structure but that's the basics of it.

Your registration.php file should look something like this:

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Your_Module',
    __DIR__
);

If all that fails try running php bin/magento setup:upgrade or clearing the caches.

5
  • You can view again my code. Where is the issue ?
    – LinoPham
    Commented Nov 16, 2015 at 11:00
  • That's strange, is the rest of the component functionality broken as well or is it just the routes? I'm wondering if the module is being ignored by Magento. Commented Nov 16, 2015 at 11:09
  • My module decrated in app/etc/config.php and after run bin/magento setup:upgrade, it have create table in database.
    – LinoPham
    Commented Nov 16, 2015 at 11:12
  • What happens if you navigate to example.com/index.php/ticket ? Could be that the permalink rewrite isn't working or enabled. Commented Nov 16, 2015 at 11:16
  • I try add new file inMagento/Catalog module have path as app/code/Magento/Catalog/Controller/Index/Demo.php , it working normally with routers as catalog/index/demo
    – LinoPham
    Commented Nov 16, 2015 at 11:20
1

I ran into the same problem. It was a failure in autoloader, empty declaration in composer.json

The problem only was in Magento 2.0.0-rc2 and is solved in newer versions.

in RC2, composer.json looks like:

"psr-0": {
        "_empty_": "app/code/"
   },

and it should be:

"psr-0": {
        "": "app/code/"
   },

see this issue to resolve your problem https://github.com/magento/magento2/issues/2381

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.