如何在zf2中使用Zend \ Session? [英] How to use Zend\Session in zf2?

查看:150
本文介绍了如何在zf2中使用Zend \ Session?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人尝试zf2吗?我无法理解在zf2中使用会话的新机制.如何在新的zend框架中读写会话?

Does anybody try zf2? I can not understand new mechanism of using sessions in zf2. How can I write and read to/from the session in new zend framework?

我在互联网上也找不到任何示例.

Also I can not find any examples in the internet.

推荐答案

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'); 

这篇关于如何在zf2中使用Zend \ Session?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆