cakephp-3.7 - 插件内的 CakePHP 3.7 Shell 命令无法执行
问题描述
namespace Admin\Shell;
use Cake\Console\Shell;
class AdminAlertShell extends Shell{
...
...
}
这里'Admin'是插件,所以我在插件文件夹结构中创建了这个文件。文件路径:/plugins/Admin/src/Shell/AdminAlertShell.php
试图在 CLI 中运行它
bin/cake admin_alert
但是抛出异常
例外:未知命令cake admin_alert
。运行cake --help
以获取有效命令的列表。在 [localpath/vendor/cakephp/cakephp/src/Console/CommandRunner.php,第 346 行]
它正在工作。但我不知道这是怎么回事。我已将 cakephp 3.5 升级到 3.7。但是,我不确定这是否会导致问题。
解决方案
我刚刚在我的项目中找到了问题的根源。
在我的插件里面有一个文件:src/Plugin.php
在这个类里面有以下几行代码:
/**
* @inheritDoc
*/
public function console(CommandCollection $commands): CommandCollection
{
// Add console commands here.
return $commands;
}
这可能是通过烘焙生成的。
我看到没有打电话给父母。在父路径中添加。
将此方法更改为如下所示:
/**
* @inheritDoc
*/
public function console(CommandCollection $commands): CommandCollection
{
// Add console commands here.
$commands = parent::console($commands);
return $commands;
}
现在调用父级并将路径添加到命令集合中。
作为旁注,我还看到中间件没有调用它的父级。
认为修复那个也是一个好主意。
作为替代方案,您可以清除该类并应使用所有默认值。
希望这可以节省我花在解决这个问题上的时间。
推荐阅读
- amazon-web-services - 是否有任何东西将 AWS::ElasticBeanstalk::Environment 链接到它创建的嵌套堆栈?
- c# - 将字符串解析为键值对C#
- python - 从python列表中的每个项目中删除单引号
- c++ - GStreamer GError to boost::system::error_code?
- python - 文本文件到python中的字典
- html - 响应式 CSS - 使 div 响应的问题
- python-3.x - 在 python 子进程中,Popen.kill() 是否是阻塞调用?
- c# - Kentico 12 (Portal) - 在后面的代码中从媒体选择中检索媒体文件信息
- matlab - 许可证密钥未显示在 MATLAB 命令提示符中
- c++ - 为什么在 constexpr 函数中有“从不使用非文字类型”规则?