我找到了解决方案。我无法向 cli 用户授予权限,但它是通过在从 CLI 运行时禁用 bjyAuthorize 来完成的。
我找到了解决方案:如何在 ZF2 CLI 应用程序中使用 BjyAuthorize? https://github.com/bjyoungblood/BjyAuthorize/issues/223
如果其他人发现此问题,以下是他们的解释:
要在从 cli 运行时禁用 bjyAuthorize,我们可以在 application.config.php 中执行如下操作。
最初不要在 application.config.php 数组中添加“BjyAuthorize”和“BjyProfiler”。检查控制台,如果没有控制台访问权限,则将它们添加到 $config 数组中。
if (!Console::isConsole()) {
array_unshift($config['modules'], 'BjyAuthorize');
array_unshift($config['modules'], 'BjyProfiler');
}
return $config;
另外,还需要检查 Application/Module.php 的 onBootstrap 方法中的控制台,如下所示
if (!Console::isConsole()) {
$authorize = $sm->get('BjyAuthorize\Service\Authorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
}
最后但并非最不重要的一点是,不要忘记导入 Console 类:
use Zend\Console\Console;