用zend framework做开发数据表认证怎么实现不了 代码贴出来了
class LoginController extends zend_Controller_action
{
public function checkAction()
{ if($this->_request->isPost()){
// 过滤用户输入
$filter = new Zend_Filter_Striptags();
$username = trim($filter->filter($this->_request->getPost('username')));
$password = trim($filter->filter($this->_request->getPost('password')));
//$bootstrap = $this->getInvokeArg('bootstrap');
//$db = $bootstrap->getResource('db');
//数据库配置数组
$params = array('host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'yh_db'
);
$db = Zend_Db::factory('pdo_mysql', $params);
// 数据库表认证
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'h3_user', 'user_name', 'user_pwd');
$authAdapter->setIdentity($username)->setCredential(md5($password));
$result = $this->_auth->authenticate($authAdapter);
if($result->isValid()) {
// 将当前用户于 h3_user 表中的记录除去 user_pwd 字段内容,其他的字段数据全部取出来
$data = $authAdapter->getResultRowObject(null, 'user_pwd');
// 这里添加当前用户的角色信息,由于 $data->roleID , 只记录了 id ,需要在 role 表里面查询 roleName
// 添加当前用户的角色名
$data->roleName = 'administrator';
// 将当前用户信息存入 Zend_Session
$this->_auth->getStorage()->write($data);
//$this->_redirect->myRedirect(‘/app/admin/index’);
echo $result->getCode();
}
else {
//$this->_view->assign(‘message’, $result->getMessages());
//print_r($result->getMessages());
//$this->_redirect->myRedirect(‘/app/admin/login’);
// 我用的 Ajax 判断登陆的所以直接 echo
echo $result->getCode();
}
}
}
}
// $bootstrap = $this->getInvokeArg('bootstrap')
//$db = $bootstrap->getResource('db');
还有这两句诗什么意思
是不是我的数据库没有连接成功啊 还是忘记导入什么文件了 就差这一点了 请你们帮忙看看