1
我在ZF1登錄控制器以下功能和工作正常,但不能口ZF2請幫我這個函數ZF2登錄功能升級到ZF2
if ($this->_request->isPost() && $userForm->isValid($_POST)) {
$data = $userForm->getValues();
//set up the auth adapter
// get the default db adapter
$db = Zend_Db_Table::getDefaultAdapter();
//create the auth adapter
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users','username', 'password');
//set the username and password
$authAdapter->setIdentity($data['username']);
$authAdapter->setCredential(md5($data['password']));
//authenticate
$result = $authAdapter->authenticate();
if ($result->isValid()) {
// store the username, first and last names of the user
$auth = Zend_Auth::getInstance();
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(
array('username' , 'first_name' , 'last_name', 'role')));
return $this->_forward('index');
} else {
$this->view->loginMessage = "Sorry, your username or
password was incorrect";
}
}
$this->view->form = $userForm;`enter code here`