Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend Framework 2身份验证不带数据库表检查_Php_Session_Authentication_Zend Framework2 - Fatal编程技术网

Php Zend Framework 2身份验证不带数据库表检查

Php Zend Framework 2身份验证不带数据库表检查,php,session,authentication,zend-framework2,Php,Session,Authentication,Zend Framework2,我正在尝试进行Zend 2经典身份验证,而不使用DbTable检查 我会解释得更清楚 我有一个自定义方法authenticate(),它能够对用户进行身份验证(独立于Zend Auth) 我创建了一个扩展Zend\Authentication\Storage\Session的自定义类 现在,我想用如下方式将数据保存到会话中: $authService->getStorage()->write($this); 问题在于在下一页调用时使用该代码: if($authService-

我正在尝试进行Zend 2经典身份验证,而不使用DbTable检查

我会解释得更清楚

  • 我有一个自定义方法authenticate(),它能够对用户进行身份验证(独立于Zend Auth)
  • 我创建了一个扩展Zend\Authentication\Storage\Session的自定义类
  • 现在,我想用如下方式将数据保存到会话中:

    $authService->getStorage()->write($this);
    
问题在于在下一页调用时使用该代码:

if($authService->hasIdentity())
它的回答是错误的

那么,如何使用自定义身份验证保存身份?我想我可以实现Zend\Authentication\Adapter\AdapterInterface,但我不知道具体如何实现

感谢您的帮助,
非常感谢:)

您可以创建如下适配器:

use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Result as AuthResult;

class MyAdapter implements AdapterInterface
{

    /**
     * @return \Zend\Authentication\Result
     */
    public function authenticate()
    {
        /* Return if can't find user */
        return new AuthResult(AuthResult::FAILURE_IDENTITY_NOT_FOUND, null);
        /* Return if success, second parameter is the identity, e.g user. */
        return new AuthResult(AuthResult::SUCCESS, $identity);
        /* Return if user found, but credentials were invalid */
        return new AuthResult(AuthResult::FAILURE_CREDENTIAL_INVALID, null);
    }
}
您可以将此适配器与ZF2 AuthenticationService一起使用,如下所示:

$auth_service = new \Zend\Authentication\AuthenticationService();
/* Where $myAdapter is a instance of the MyAdapter class above */
$auth_service->setAdapter($myAdapter);