I encountered a problem where my new module is not found when I tried to browse it.
Heres the detail of the code.
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="Ced_TermsAndServices" setup_version="1.0.0"> </module> </config>
registration.php
<?PHP \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Ced_TermsAndServices', __DIR__ );
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>
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? Thank you in advance.
Hi,
Please check whether you have successfully ran the module deployment commands or not.
php bin/magento module:enable Ced_TermsAndServices
php bin/magento setup:upgrade
php bin/magento s:d:c
php bin/magento s:s:d -f
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
I think you forgot to add Project base URL in your URL :
http://localhost/{PROJECT_FOLDER}/cstermsandservices/index/index
Hi thank you for responding to my question.
I can confirm that the modules have been enabled and I have tried all commands you provided. But still, the same result is showing.
Hi thank you for your answer. But it does not fix the issue.
Hi @yumedream19e2c,
Please correct the directory structure in controller file.
Ced\CsTermsAndServices\Controller\Index;
To
Ced\TermsAndServices\Controller\Index;
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
Please fix namespace and try URL with project folder name