我有兴趣拥有可以通过所有视图和控制器访问的数据,但是当浏览器关闭时或在注销操作上时,我想要清除此数据。

此原因是因为我希望只有设置变量时才要工作。 例如:

public function adminAction(){
    if ($rol_type=='admin'){
        $this->renderScript('index/admin.phtml');
    }
    else{
        $this->renderScript('index/adminLogin.phtml');
    }
}
.

我还希望在没有设置为admin的情况下无法访问admin.phtml视图,因此没有人可以更改URL并访问管理面板。

我一直在阅读Zend Framework的2个关于会话的文档,但会话模块里面有很多东西,所以我不知道要使用什么,或者在哪里寻找。

如果你能告诉我达到我的目标的最佳方式,我也会非常感激(因为我不确定这是做我想做的最好的方法)。

有帮助吗?

解决方案

您可以使用:

use Zend\Session\Container;
.

在控制器中:

$user_session = new Container('mySession');
$user_session->key = "Your Value";
.

此键可以传递给您的视图或其他模型和控制器。

检索我们必须这样做:

$user_session = new Container('mySession');
$keyValue = $user_session->key;   //here you will get the value stored above
.

希望有助于

感谢

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top