Zend 2-用户会话不起作用


Zend 2 - User session does not work

在读取用户模型中记录的用户会话时遇到困难。

当从任何其他模型中检索用户数据时,它都能完美地工作。

模块.PHP

'session' => function ($sm) {
                $config = $sm->get('config');
                if (isset($config['session'])) {
                    $session = $config['session']['config']['options']['name'];
                    //Various Session options
                    $manager = new 'Zend'Session'SessionManager();                        
                     if(filter_input(INPUT_SERVER, 'APPLICATION_ENV') === 'production'){
                        $manager->getConfig()
                                ->setCookieHttpOnly(true)
                                ->setCookieSecure(false);
                        $manager->start();
                    }
                    return new Session($session);
                }
            },

BaseTable.php

    public function getIdentity($property = null) {
    $storage = $this->getServiceLocator()->get('session');
    if (!$storage) {
        return false;
    }
    $data = $storage->read();
    if ($property && isset($data[$property])) {
        return $data[$property];
    }
    return $data;
}

当我调用tb_usuario实例化的getIdentity函数时,我得到了以下错误:

致命错误:对中的非对象调用成员函数get()C: ''wamp''www''sigaAvaliacoes''module''application''src''application''Model''BaseTable.php在线73

对不起我的英语,谢谢!

对不起,伙计们,我在Module.php中发现了问题,我没有实例serviceLocator:

'Usuario' => function($sm) {
                $tableGateway = new TableGateway('tb_usuario', $sm->get('db_adapter_main'));
                return new Model'Usuario($tableGateway);
            },

现在工作:

'Usuario' => function($sm) {
                $tableGateway = new TableGateway('tb_usuario', $sm->get('db_adapter_main'));
                $updates = new Model'Usuario($tableGateway);
                $updates->setServiceLocator($sm);
                return $updates;
            },

感谢=D