-2
我想用用戶名或電子郵件地址登錄。我現在可以用用戶名登錄。我如何用ZF2做到這一點? (我用doctirine)ZF2 AuthenticationService
謝謝
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
// Do the same you did for the ordinar Zend AuthService
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($post['username']); //$data['usr_name']
$adapter->setCredentialValue($post['password']); // $data['usr_password']
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
$identity = $authResult->getIdentity();
$authService->getStorage()->write($identity);
$time = 1209600; // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
if ($post['rememberme']) {
$sessionManager = new \Zend\Session\SessionManager();
$sessionManager->rememberMe($time);
}
}
1.格式化問題更好2.提高投票率 – tasmaniski 2014-10-01 12:21:48