Zend 框架 3 中的身份验证服务
Authenticationservice in Zend framework 3
ZF3中的认证服务还可用吗?如果不是,新的名称是什么?效果一样吗?
我收到错误消息:
Class 'Import\AuthenticationService' not found
我让composer抢过来的:
我也在 zend-framework.com 上搜索过,无论是 migration topics 还是找不到任何信息。
因为我是ZF1过来的所以也想问一下我的想法对不对。我在 Module.php:
中实现了 authenticationService
作为工厂
'factories' => [
Model\Authentication::class => function ($container){
$auth = new AuthenticationService();
$dbAdapter = $container->get(AdapterInterface::class); // AND aktiv != 0
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 't_user','accessname','password', 'SHA2(?, 512)');
$auth->setAdapter($dbTableAuthAdapter);
return $auth;
},
我将身份验证服务连接到我的控制器 (Module.php):
Controller\IndexController::class => function($container) {
return new Controller\IndexController(
$container->get(Model\UserTable::class),
$container->get(Model\Authentication::class),
$container->get(AdapterInterface::class)
);
},
我的 Indexcontroller
如下所示:
class IndexController extends AbstractActionController
{
private $loginTable;
private $authService;
private $db;
public function __construct(UserTable $loginTable, AuthenticationService $authService, AdapterInterface $db)
{
//$db=$this->db ;
$this->loginTable = $loginTable;
$this->authService = $authService;
$this->db=$db;
}
//Anzeigen der importierten Dateien
public function indexAction()
{
$berechtigung = (int) $this->loginTable->getBerechtigung($this->authService->getIdentity());
if(!$this->authService->hasIdentity() || $berechtigung > 1){ // 1 = Administrator
return $this->redirect()->toRoute('user', ['action' => 'login']);
}
else {
return $this->redirect()->toRoute('project', ['action' => 'index']);
}
}
这是实施身份验证的正确方法吗?
要安装 zend-authentication,请在您的终端中输入此内容
composer require zendframework/zend-authentication
关于你这样的错误信息
Class 'Import\AuthenticationService' not found
你应该像这样通过完整的命名空间使用它
use Zend\Authentication\AuthenticationService;
ZF3中的认证服务还可用吗?如果不是,新的名称是什么?效果一样吗?
我收到错误消息:
Class 'Import\AuthenticationService' not found
我让composer抢过来的:
我也在 zend-framework.com 上搜索过,无论是 migration topics 还是找不到任何信息。
因为我是ZF1过来的所以也想问一下我的想法对不对。我在 Module.php:
中实现了authenticationService
作为工厂
'factories' => [
Model\Authentication::class => function ($container){
$auth = new AuthenticationService();
$dbAdapter = $container->get(AdapterInterface::class); // AND aktiv != 0
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 't_user','accessname','password', 'SHA2(?, 512)');
$auth->setAdapter($dbTableAuthAdapter);
return $auth;
},
我将身份验证服务连接到我的控制器 (Module.php):
Controller\IndexController::class => function($container) {
return new Controller\IndexController(
$container->get(Model\UserTable::class),
$container->get(Model\Authentication::class),
$container->get(AdapterInterface::class)
);
},
我的 Indexcontroller
如下所示:
class IndexController extends AbstractActionController
{
private $loginTable;
private $authService;
private $db;
public function __construct(UserTable $loginTable, AuthenticationService $authService, AdapterInterface $db)
{
//$db=$this->db ;
$this->loginTable = $loginTable;
$this->authService = $authService;
$this->db=$db;
}
//Anzeigen der importierten Dateien
public function indexAction()
{
$berechtigung = (int) $this->loginTable->getBerechtigung($this->authService->getIdentity());
if(!$this->authService->hasIdentity() || $berechtigung > 1){ // 1 = Administrator
return $this->redirect()->toRoute('user', ['action' => 'login']);
}
else {
return $this->redirect()->toRoute('project', ['action' => 'index']);
}
}
这是实施身份验证的正确方法吗?
要安装 zend-authentication,请在您的终端中输入此内容
composer require zendframework/zend-authentication
关于你这样的错误信息
Class 'Import\AuthenticationService' not found
你应该像这样通过完整的命名空间使用它
use Zend\Authentication\AuthenticationService;