Php 如何从Zend_Auth获取用户id

Php 如何从Zend_Auth获取用户id,php,zend-framework,Php,Zend Framework,我在使用zend获取用户id时遇到了大问题 我的身份验证登录代码: if($form->isValid($this->getRequest()->getPost())){ $adapter = new Zend_Auth_Adapter_DbTable( null, 'sprzedawca', 'email', 'haslo',

我在使用zend获取用户id时遇到了大问题

我的身份验证登录代码:

if($form->isValid($this->getRequest()->getPost())){
        $adapter = new Zend_Auth_Adapter_DbTable(
                null,
                'sprzedawca',
                'email',
                'haslo',
                'MD5(CONCAT(?, salt))'
        );

        $adapter->setIdentity($form->getValue('email'));
        $adapter->setCredential($form->getValue('haslo')); 

        $auth = Zend_Auth::getInstance();
        $wynik = $auth->authenticate($adapter);

        if($wynik->isValid()){
            //return $this->_helper->FlashMessenger('Pomyślnie zalogowano');
            return $this->_helper->redirector(
                    'index',
                    'sprzedawca',
                    'default'
            );
现在,当我尝试使用以下命令写入用户id时:

Zend_Auth::getInstance()->getIdentity()
我只得到“用户名”,但我想得到用户id

Zend_Auth::getInstance()->getIdentity()->user_id

不太管用。

我通过谷歌搜索找到了这个,试试看

Zend_Auth::getInstance()->getIdentity()->User_ID

好吧,我在登录时没有储存物品

应该是:

if($wynik->isValid()){
   $storage = $auth->getStorage();
   $storage->write($adapter->getResultRowObject('sprzedawca_id'));

现在运行得很好

我现在看不到您的数据库方案,但我可以告诉您,这对我来说很有效

<?php 

    $auth = Zend_Auth::getInstance();
    $userId = $auth->getIdentity()->id;//user_id OR id depending your primary key of the user table.
    echo $userId;

 ?>


注意:-$userId=$auth->getIdentity()->id//id必须写入,因为它是您的用户表,否则它将不起作用。请注意:尝试获取C:\xampp\htdocs\spms\application\controllers\SprzedawcaController.php中的非对象属性(第33行),这很公平,很抱歉。我只是猜测我对这个API一无所知?就我个人而言。