Reputation: 219
I am new in magento 2, following a tutorial in the official documentation try to create a simple view, but when I log in my route throws me error 404
This is the structure of my directory
This is what I have in my files
view.php
<?php
namespace Learning\HelloPage\Controller\Page;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\Result\JsonFactory;
class View extends Action
{
/**
* @var JsonFactory
*/
protected $resultJsonFactory;
public function __construct(Context $context, JsonFactory $resultJsonFactory)
{
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context);
}
public function execute()
{
$result = $this->resultJsonFactory->create();
$data = ['message' => 'Hello World'];
return $result->setData($data);
}
}
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="Learning" frontName="test">
<module name="Learning_HelloPage" />
</route>
</router>
</config>
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="Learning_HelloPage" setup_version="0.0.1" />
</config>
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Learning_HelloPage',
__DIR__
);
In addition to this in the console I run the following command for the cache
php bin/magento cache:flush
After all this when entering the next path on my server
I get 404 error, but in the title that followed, it is exactly like that. What error do I have and how can I solve it?
Upvotes: 0
Views: 129
Reputation: 757
The url path should be
And make sure you run this command to install your module:
php bin/magento s:up
And then you can check your module is enabled or not by this:
php bin/magento module:status Learning_HelloPage
Cheers
Upvotes: 4