因为 magento 2 的这个模块不起作用?

Because this module of magento 2 does not work?

我是 magento 2 的新手,按照官方文档中的教程尝试创建一个简单的视图,但是当我登录我的路线时抛出错误 404

这是我的目录结构

这是我的文件中的内容

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__ 
);

除此之外,我在控制台中 运行 以下命令用于缓存

php bin/magento cache:flush

在我的服务器上输入下一个路径时完成所有这一切

http://localhost/magento/test/view/page

我收到 404 错误,但在随后的标题中,它正是这样。我有什么错误,我该如何解决?

url 路径应该是

http://localhost/magento/test/page/view

并确保你运行这个命令来安装你的模块:

php bin/magento s:up

然后您可以通过以下方式检查您的模块是否已启用:

php bin/magento module:status Learning_HelloPage

干杯