public function loginAction() {
$auth = Zend_Auth::getInstance();
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();
$request=$this->getRequest();
$authAdapter = new Zend_Auth_Adapter_DbTable($DB);
$authAdapter->setTableName('user')
->setIdentityColumn('uname')
->setCredentialColumn('password');
$uname = $request->getParam('uname');
$pass = $request->getParam('password');
$authAdapter->setIdentity($uname);
$authAdapter->setCredential($pass);
$result = $authAdapter->authenticate($authAdapter);
$this->view->assign('auth',$result);
if($result->isValid()) {
$data = $authAdapter->getResultRowObject(null,'pass');
$auth->getStorage()->write($data);
//$this->view->assign('dbdata',$data);
$userInfo = new Zend_Session_Namespace('userInfo');
$userInfo->userType = 'admin';
//$this->_redirect('/admin/adminhome');
} else {
$this->_redirect('/admin/index?fail=true');
}
$data = $authAdapter->getResultRowObject(null,'pass');
这里$data
将返回一个像这样的对象:
stdClass Object ( [id] => 12 [uname] => user [password] => user [type] => user )
我想将其转换为数组。只是尝试toArray()
了功能,但徒劳无功。我的要求是像这样检查用户类型:
if($data['type']=='admin'){
do something
} else {
do something
}
谢谢