【发布时间】:2025-12-07 08:25:01
【问题描述】:
我是 Magento 2 的新手,我正在创建一个打印 hello world 的自定义 CLI 命令,但是当我看到列表 php bin/magento list 时,它没有显示我添加的命令,而是向我抛出了这个错误:
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "training" namespace.
这是我为使 CLI 命令正常工作所做的事情,我不认为我错过了一些东西:
app/code/SimplifiedMagento/FirstModule/Console/Command/HelloWorld.php
<?php
namespace SimplifiedMagento\FirstModule\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class HelloWorld extends Command
{
public function configure()
{
$this->setName("training:hello_world");
$this->setDescription("the command prints out hello world");
parent::configure();
}
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Hello World');
}
}
app/code/SimplifiedMagento/FirstModule/etc/frontend/di.xml
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="hello_world" xsi:type="object">
SimplifiedMagento\FirstModule\Console\Command\HelloWorld</item>
</argument>
</arguments>
</type>
我不知道哪里出错了,谁能帮帮我?
我的命令基本上会说training:hello_world
【问题讨论】: