【问题标题】:Magento 2 New Module Route Not Found未找到 Magento 2 新模块路由
【发布时间】:2020-07-06 15:28:40
【问题描述】:

我在尝试浏览新模块时遇到了一个问题。

这里是代码的详细信息。

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;
    }
}

预期的路线应该是 http://localhost/cstermsandservices/index/index

但结果是 404 not found。 有什么解决办法吗?

【问题讨论】:

    标签: php magento2


    【解决方案1】:

    1) 确保遵循供应商/模块名称 vendor_module-name 约定(如果您想遵循当前目录结构,则模块名称应为 Ced_CsTermsAndServices) 2) module.xml 文件名全部小写

    希望这会奏效 快乐的Magento

    【讨论】:

    • 是的,我确实把它放在那里
    • 还没有@Adarsh Shukla
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多