Dear Magento Community,
I've tried to create a simple custom page, tried out many tutorials, and read a lot of solutions on forums, but none of them work for me. My module can be enabled but I keep getting redirected when I go to the URL path I've created. Here is the content of my files (with their paths) so can someone please check it out, I need the solution urgently
app/code/ZenDev/HelloZenDev/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Hello_ZenDev',
__DIR__
);
app/code/ZenDev/HelloZenDev/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="Hello_ZenDev" setup_version="0.0.1"></module>
</config>
app/code/ZenDev/HelloZenDev/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="zendev_hellozendev" frontName="zendev"> <module name="Hello_ZenDev" /> </route> </router> </config>
app/code/ZenDev/HelloZenDev/Controller/Page/View.php
<?php
declare(strict_types=1);
namespace ZenDev\HelloZenDev\Controller\Page;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\ResultFactory;
class View extends Action
{
public function execute()
{
/** @var Json $jsonResult */
$jsonResult = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$jsonResult->setData([
'message' => 'Hello ZenDev!'
]);
return $jsonResult;
}
}I go to the page http://localhost:8080/zendev/page/view and I'm redirected to 404 page (keep in mind I've setup my magento page to be on localhost:8080 and installation worked fine)
Thankful in advance
Solved! Go to Solution.
Hello @berinabandede1
Hello @berinabandede1
My URL was correct because that's the only store I have, but the problem was in the naming of my folders as you've mentioned above
Thank you so much!