我是zf2的新手。 zfcuser的设置与安装指南一样。我可以注册,登录和注销。
我为前端和后端创建了模块。我试图检查用户是否登录后端 - 管理员和所有子模块。
我试图加入
$sm = $app->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');
if (!$auth->hasIdentity()) {
//redirect to login page
}
在我的admin / module.php函数onBootStrap
中它确实检查了登录,但不仅是管理员,还是整个模块,包括前端。
我只需要检查admin模块的登录名,以及admin的所有子模块。
无法弄清楚如何。请帮忙
答案 0 :(得分:0)
<?php
namespace AdminModule;
use Zend\Authentication\AuthenticationService;
return array(
__NAMESPACE__ => array(
'params' => array(),
'service_manager' => array(
'invokables' => array(
'Zend\Authentication\AuthenticationService' => 'Zend\Authentication\AuthenticationService',
),
),
'services' => array(
// Keys are the service names
// Values are objects
'Auth' => new AuthenticationService(),
),
),
);
$this->auth = new AuthenticationService();
if($this->auth->hasIdentity()){
$this->userid = $this->auth->getIdentity();
}
您也可以使用工厂。
$this->zfcUserAuthentication()->hasIdentity()