You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Magento自定义AlanStorm_HelloWorld控制器无法工作排查求助

Magento自定义控制器无法正常运行

尝试创建Magento自定义控制器,但无法正常访问。已执行magento setup:di:compile、magento c:f、magento c:c命令,且config.php中模块已启用,问题仍未解决。

相关文件代码

控制器文件(AlanStorm/HelloWorld/Controller/Hello/World.php)

<?php

namespace AlanStorm\HelloWorld\Controller\Hello;

use Magento\Framework\App\ActionInterface;

class World implements ActionInterface
{
    public function execute()
    {
        echo "Hello World!";
    }
}

module.xml(AlanStorm/HelloWorld/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="AlanStorm_HelloWorld">
    </module>
</config>

routes.xml(AlanStorm/HelloWorld/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="hello_world" frontName="hello_world">
            <module name="AlanStorm_HelloWorld" />
        </route>
    </router>
</config>

registration.php(AlanStorm/HelloWorld/registration.php)

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'AlanStorm_HelloWorld',
    __DIR__
);

补充信息

  • 运行结果:访问对应路由时出现404错误页面
  • 模块文件结构:
    • AlanStorm/HelloWorld/
      • Controller/Hello/World.php
      • etc/module.xml
      • etc/frontend/routes.xml
      • registration.php

内容的提问来源于stack exchange,提问作者Anonymus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 00:15:44