Question

I am interested in having data that can be access through all my views and controllers, but I would like this data to be cleared when the browser is closed or on a logout action.

The reason for this is because I want my views to work only if a variable is set. eg:

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

I would like also that the admin.phtml view can't be accesed without the variable being set to admin, so that no one can just change the URL and acces admin panel.

I've been reading the zend framework's 2 documentation about session but there is a lot of stuff inside the session module, so I don't know what to use, or where to look for.

I also would be very grateful if you could tell me what is the best way to achive my goal (cause I'm not sure if this is the best way to do what I want to do).

Was it helpful?

Solution

You can use :

use Zend\Session\Container;

In Controller:

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

This key can be passed to your view or other models and controllers.

For retrieving we have to do like:

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

Hope that helps

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top