Sam
Sam

Reputation: 557

Magento 2 New Module Route Not Found

I encountered a problem where my new module is not found when I tried to browse it.

Here is the detail of the code.

Ced/CsTermsAndServices/etc/Module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Ced_TermsAndServices" setup_version="1.0.0">
    </module>
</config>

Ced/CsTermsAndServices/registration.php

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

Ced/CsTermsAndServices/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 frontName="cstermsandservices" id="cstermsandservices">
            <module name="Ced_TermsAndServices"/>
        </route>
    </router>
</config>

Ced/CsTermsAndServices/Controller/Index/Index.php

<?php
namespace Ced\CsTermsAndServices\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory)
    {
        $this->_pageFactory = $pageFactory;
        return parent::__construct($context);
    }

    public function execute()
    {
        echo "Hello World";
        exit;
    }
}

The expected route supposed to be http://localhost/cstermsandservices/index/index

But the result ended up as 404 not found. Any fix to this?

Upvotes: 0

Views: 430

Answers (1)

Adarsh Shukla
Adarsh Shukla

Reputation: 136

1)make sure you have vendor/module-name vendor_module-name convention is followed( in your case modules name should be Ced_CsTermsAndServices if you want to follow current directory structure) 2) module.xml file name should be in all lower case

Hope this will work Happy Magento

Upvotes: 2

Related Questions