0

私はhttp://framework.zend.com/manual/en/zend.session.savehandler.dbtable.htmlを使用しています。

問題は、ユーザーを削除するときに、ログアウトするためにそのユーザーのセッションを削除したいのですが、彼のセッションが何であるかわからないということです...

zendセッションテーブルオプションにカスタム列を追加して、ユーザーのIDを保存する方法が見つかりません

4

1 に答える 1

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;
    }
}

詳細については、このHOWTOをご覧ください。

于 2011-03-25T13:17:30.307 に答える