0

Actually I am storing on value in the container in index action then i am fetching that value in same action but i am not able to fetch that value in another action of that same controller as well as in another controller...am I missing Something?

This is my code..

  • IndexController

    class IndexController extends AbstractActionController  {
    
    public function indexAction() {
    
        $session=new Container('temp');
        $session->username="bhavik";
    
        error_log("in index Controller value=$session->username");
        return new ViewModel();
      }
    public function welcomeAction() {
    
         $session = new Container('temp');
         error_log("in index controller welcome action value==".$session->username);
         $username = $session->username;
         return new ViewModel();
      }
    }
    

this is the configuration in

  • module.php

    public function initSession($config)
     {
    $sessionConfig = new SessionConfig();
    $sessionConfig->setOptions($config);
    $sessionManager = new SessionManager($sessionConfig);
    $sessionManager->start();
    Container::setDefaultManager($sessionManager);
    }
    
         public function onBootstrap(MvcEvent $e)
    {
    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);
    $this->initSession(array(
    //            'remember_me_seconds' => 240,
        'use_cookies' => true,
        'cookie_lifetime' => 2592000,
    //            'cookie_httponly' => true,
        'gc_maxlifetime' => 2592000
    ));
    }
    

this is it and all common configs and use.. I am able fetch the value of $session->username in index action but not in the welcome action..

Any help will be appreciated.

Bhavik Joshi
  • 2,557
  • 6
  • 24
  • 48
  • Try to `print_r($_SESSION)` in `indexAction` after `$session->username="bhavik"` line. Do you have `username` key here? – Rodin Vasiliy Mar 21 '15 at 10:29
  • yeah it is there see this Array ( [__ZF] => Array ( [_REQUEST_ACCESS_TIME] => 1427087263.14 ) [temp] => Zend\Stdlib\ArrayObject Object ( [storage:protected] => Array ( [username] => bhavik ) [flag:protected] => 2 [iteratorClass:protected] => ArrayIterator [protectedProperties:protected] => Array ( [0] => storage [1] => flag [2] => iteratorClass [3] => protectedProperties ) ) ) – Bhavik Joshi Mar 23 '15 at 05:08
  • Do you have PHPSESSID cookie? Is it persists between queries? Looks like your code is OK, but some problems with environment. – Rodin Vasiliy Mar 23 '15 at 11:57
  • I have installed the zend framework again now its working.. – Bhavik Joshi Mar 24 '15 at 06:23
  • and yeah I do have that cookies..but i think it might be destroying the session after calling the controller ..don't know what was the problem there? – Bhavik Joshi Mar 24 '15 at 06:33

0 Answers0