且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在zf2中使用Zend \ Session?

更新时间:2023-12-03 23:14:58

zf2会话用法的一些示例:

Some examples of zf2 sessions usage:

会话创建:

use Zend\Session\Container;
$session = new Container('base');

检查会话中是否存在密钥:

Check that key exists in session:

$session->offsetExists('email')

通过密钥从会话中获取价值:

Getting value from the session by key:

$email = $session->offsetGet('email');

设置会话中的值:

$session->offsetSet('email', $email);

未设置会话中的值:

$session->offsetUnset('email');

其他使用会话的简单方法是:

And other easy way to use session are:

$session = new Container('foo');

//这些都是同一末端的等效手段

// these are all equivalent means to the same end

$session['bar'] = 'foobar';

$session->bar = 'foobar';

$session->offsetSet('bar', 'foobar');