我正在使用http://framework.zend.com/manual/en/zend.session.savehandler.dbtable.html,
问题是,当我删除用户时,我想删除他的会话以便将他登出,但我不知道他的会话是什么......
我找不到将自定义列添加到zend会话表选项的方法,以便它可以保存用户的id
答案 0 :(得分:0)
您必须使用Zend_Auth
。你可以使用
Zend_Auth::getInstance ()->clearIdentity ();
将用户注销。
这就是我的AuthenticationController的样子:
class Default_AuthenticationController extends Zend_Controller_Action {
public function init() {
}
public function loginAction() {
if (Zend_Auth::getInstance ()->hasIdentity ()) {
$this->_redirect ( 'index/index' );
}
$request = $this->getRequest ();
$form = new Default_Form_LoginForm ();
if ($request->isPost ()) {
if ($request->getPost ( 'username' ) != "") {
$username = $request->getPost ( 'username' );
$password = $request->getPost ( 'password' );
$authAdapter = $this->getAuthAdapter ();
$authAdapter->setIdentity ( $username )
->setCredential ( $password );
$auth = Zend_Auth::getInstance ();
$result = $auth->authenticate ( $authAdapter );
}
}
$this->view->form = $form;
}
public function logoutAction() {
Zend_Auth::getInstance ()->clearIdentity ();
$this->_redirect ( 'index/index' );
}
private function getAuthAdapter() {
$authAdapter = new Zend_Auth_Adapter_DbTable (
Zend_Db_Table::getDefaultAdapter () );
$authAdapter->setTableName ( 'users' )
->setIdentityColumn ( 'email' )
->setCredentialColumn ( 'password' )
->setCredentialTreatment ( 'SHA1(CONCAT(?,salt))' );
return $authAdapter;
}
}
观看此HOW TO以获取更多详细信息。