2016-01-06 66 views
0

我在閱讀用戶模型中記錄的用戶會話時遇到困難。Zend 2 - 用戶會話不起作用

當從任何其他模型檢索用戶數據時,它可以很好地工作。

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

當我打電話getIdentity函數,其中tb_usuario實例我得到這個錯誤:

Fatal error: Call to a member function get() on a non-object in C:\wamp\www\sigaAvaliacoes\module\application\src\Application\Model\BaseTable.php on line 73

對不起我的英語,謝謝!

回答

0

對不起球員,我發現這個問題,在我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