olegkrivtsov / using-zf3-book-samples

Samples for the Using Zend Framework 3 book
142 stars 100 forks source link

Users module's issue #62

Closed juliangorge closed 4 years ago

juliangorge commented 4 years ago

Hello there! I can see Users module (userdemo) is creating session data files everytime an user just connect to home page without login. If I debug, I see User's module is loaded before Application's module.

`<?php namespace User;

use Zend\Mvc\MvcEvent; use Zend\Mvc\Controller\AbstractActionController; use User\Controller\AuthController; use User\Service\AuthManager;

class Module { ... public function onBootstrap(MvcEvent $event) { // Get event manager. $eventManager = $event->getApplication()->getEventManager(); $sharedEventManager = $eventManager->getSharedManager(); // Register the event listener method. $sharedEventManager->attach(AbstractActionController::class, MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch'], 100);

    $sessionManager = $event->getApplication()->getServiceManager()->get('Zend\Session\SessionManager');

    $this->forgetInvalidSession($sessionManager);
}

protected function forgetInvalidSession($sessionManager) 
{
    try {
        $sessionManager->start();
        return;
    } catch (\Exception $e) {
    }
    /**
     * Session validation failed: toast it and carry on.
     */
    // @codeCoverageIgnoreStart
    session_unset();
    // @codeCoverageIgnoreEnd
}

}

?>`

My module.config.php

`<?php return [ 'Zend\Navigation', 'Zend\Mvc\Plugin\FilePrg', 'Zend\Mvc\Plugin\FlashMessenger', 'Zend\Mvc\Plugin\Identity', 'Zend\Mvc\Plugin\Prg', 'Zend\Form', 'Zend\I18n', 'Zend\ServiceManager\Di', 'Zend\Db', 'Zend\Session', 'Zend\Router', 'Zend\Validator', 'DoctrineModule', 'DoctrineORMModule', 'ZendDeveloperTools', 'Application', 'Users' ];

?> `

How can I fixed this? Thank you!

juliangorge commented 4 years ago

I've fixed it upgrading to Laminas MVC, this my new Module.php

`<?php

/**

namespace Admin;

use Laminas\Mvc\MvcEvent; use Laminas\Mvc\Controller\AbstractActionController; use Admin\Controller\AuthController; use Admin\Service\AuthManager;

class Module { /**