Give permission for bjyauthorize to run mvc application of ZF2 from CLI

白昼怎懂夜的黑 提交于 2019-12-05 17:36:40

I found the solution. I am not able to give permission for cli user but it has done by disabling bjyAuthorize while running from CLI.

I found solution on this: How to use BjyAuthorize in ZF2 CLI application?

Here is the explanation for others if they found this issue:

To disable bjyAuthorize while running from cli, we can do like below in application.config.php.

Do not add "BjyAuthorize" and "BjyProfiler" in your application.config.php array initially. Check for console, if not console access then add them in $config array.

if (!Console::isConsole()) {
    array_unshift($config['modules'], 'BjyAuthorize');
    array_unshift($config['modules'], 'BjyProfiler');
}
return $config;

Also it is necessary to check Console in Application/Module.php's onBootstrap method like below

if (!Console::isConsole()) {
        $authorize = $sm->get('BjyAuthorize\Service\Authorize');
        $acl = $authorize->getAcl();
        $role = $authorize->getIdentity();
    }

Last but not least, do not forget to import Console class:

use Zend\Console\Console;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!