亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Magento 2 中創建自定義 CLI 命令讓我出錯

在 Magento 2 中創建自定義 CLI 命令讓我出錯

PHP
胡子哥哥 2022-10-28 16:07:16
我是 Magento 2 的新手,我正在創建一個打印 hello world 的自定義 CLI 命令,但是當我看到列表時 php bin/magento list,它沒有顯示我添加的命令,而是向我拋出了這個錯誤: [Symfony\Component\Console\Exception\CommandNotFoundException]    There are no commands defined in the "training" namespace.  以下是我為使 CLI 命令正常工作所做的事情,我不認為我錯過了一些東西:應用程序/代碼/SimplifiedMagento/FirstModule/Console/Command/HelloWorld.php<?phpnamespace 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');    }}應用程序/代碼/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
查看完整描述

1 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

經過一番研究,我發現我必須在我的 etc 文件夾中創建一個單獨的 di.xml 文件,而不是 etc/frontend/di.xml


我已經剪切了命令的 di.xml 文件的代碼,并在 etc 文件夾中創建了一個新的文件 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>


查看完整回答
反對 回復 2022-10-28
  • 1 回答
  • 0 關注
  • 109 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號