0

私は ZF2 に取り組んでおり、認証用に独自のストレージを開発しましたが、新しい永続変数 (セッションのようなもの) を追加する方法を知りたいです。

Look My Auth Storage :

  <?php

namespace Application\Model;

use Zend\Authentication\Storage;
use Zend\Authentication\Storage\StorageInterface;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
use Application\Model\User;

class MyAuthStorage implements Storage\StorageInterface, ServiceManagerAwareInterface
{

    protected $storage;
    protected $userTable;
    protected $resolvedIdentity;
    protected $serviceManager;


    public function isEmpty() {
        [...]
    }

    public function read() {
        [...]
    }

    public function write($contents) {
        [...]
    }

    public function clear() {
        [...]
    }

    public function getStorage() {
        [...]
    }

    public function setStorage(Storage\StorageInterface $storage) {
        [...]
    }

    public function getUserTable() {
        [...]
    }

    public function getServiceManager() {
        [...]
    }

    public function setServiceManager(ServiceManager $serviceManager) {
        [...]
    }
}

ストレージにfooという変数を追加したい(私のセッション?)

これを試してみましたが、うまくいきません:

protected $foo;
        public function setFoo($value) {
            $this->foo= $value;
        }

        public function getFoo() {
            return $this->foo;
        }

何か案は ?

4

3 に答える 3

1

最終ログイン時刻の書き方の良い例。

namespace Application\Model;

use Zend\Authentication\Storage;

class AuthStorage extends Storage\Session
{

    public function setRememberMe($rememberMe = 0, $time = 1209600)
    {
        if ($rememberMe == 1) {
            $this->session->getManager()->rememberMe($time);
        }
    }

    public function forgetMe()
    {
        $this->session->getManager()->forgetMe();
    }

    public function lastLogin()
    {
        $this->session->{$this->getMember()}->last_login = time();
    }

}
于 2014-04-05T17:43:50.630 に答える