我在ZF1登录控制器中有以下功能,工作正常但无法移植到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`