Magento 2 新模块路由未找到

我遇到一个问题,当我尝试浏览新模块时找不到它。


这是代码的详细信息。


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。有什么解决办法吗?


MMTTMM
浏览 71回答 1
1回答

芜湖不芜

1)确保遵循供应商/模块名称供应商模块名称约定(在您的情况下,如果您想遵循当前目录结构,模块名称应为Ced_CsTermsAndServices)2)module.xml文件名应全部小写希望这能成功 Magento 快乐
打开App,查看更多内容
随时随地看视频慕课网APP