PhalconPHP无法在另一个控制器中获取会话值

PhalconPHP无法在另一个控制器中获取会话值,php,session,phalcon,Php,Session,Phalcon,我正在使用PhalconPHP并在登录后在会话中存储值,如下所示 $this->session->start(); $this->session->set('auth', array( 'dealer_id' => $dealers->getDealerId(), 'username' => $dealers->getUserName(), 'language_id' => $deal

我正在使用PhalconPHP并在登录后在会话中存储值,如下所示

$this->session->start();
    $this->session->set('auth', array(
        'dealer_id' => $dealers->getDealerId(),
        'username'  => $dealers->getUserName(),
        'language_id' => $dealers->getLanguageId(),
        'dealername'  => $dealername,
    ));

    session_write_close();
它在会话中设置值,即使在之后尝试打印

print_r($this->session->get('auth'))
它回来了

Array
(
    [dealer_id] => 78
    [username] => swiftmailcomm
    [language_id] => 1
    [dealername] => Swiftmail Communication
)
但是,当我尝试使用
ControllerBase
中的
$this->session->get('auth')
在某些操作中获取会话值时,它不会返回任何内容。它似乎被摧毁了

Php

public function registerServices(\Phalcon\DiInterface $di)
{
    $di->set('dispatcher',function(){

        $eventsManager = new EventsManager;

        /**
         * Check if the user is allowed to access certain action using the SecurityPlugin
         */
        $eventsManager->attach('dispatch:beforeDispatch', new SecurityPlugin);


        /**
         * Handle exceptions and not-found exceptions using NotFoundPlugin
         */
        $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin);

        $dispatcher = new MvcDispatcher;
        $dispatcher->setEventsManager($eventsManager);
        $dispatcher = new \Phalcon\Mvc\Dispatcher();
        $dispatcher->setDefaultNamespace("NBBD_SkyWebTech\Dealer\Controllers\\");
        return $dispatcher;
    });
    /**
     * Read configuration
     */
    $config = include __DIR__ . "/config/config.php";

    //Register Volt as a service
    $di['view'] = function () use ($config) {

        $view = new View();
        $view->setViewsDir($config->application->viewsDir);
        //activating volt engine
        $view->registerEngines(array(
            ".volt" => 'voltService'
        ));
        return $view;
    };
    $di->set('voltService', function($view, $di) use ($config) {

        $volt = new Volt($view, $di);
        $volt->setOptions(array(
            "compiledPath" => $config->application->voltCacheDir,
            'compiledSeparator' => '_',
            "compiledExtension" => ".compiled"
        ));
        return $volt;
    });

     /*
     * Setting up the view component

    $di['view'] = function () use ($config) {
        $view = new View();
        $view->setViewsDir($config->application->viewsDir);
        //activating volt engine
        $view->registerEngines(array(
            ".phtml" => 'voltService'
        ));
        return $view;
    }; */
    //Set the views cache service
    $di->set('viewCache', function() use ($config) {

        // Cache the files for 1hour using a Output frontend
        $frontCache = new Output(array(
            "lifetime" => 3600
        ));
        //Cache data for one day by default
        $cache = new File($frontCache, array(
            "cacheDir" => $config->application->cacheDir
        ));

        return $cache;
    });

    //Model Cache
    $di->set('modelsCache', function() use ($config) {

        //Cache data for one day by default
        $frontCache = new \Phalcon\Cache\Frontend\Data(array(
            "lifetime" => 3600
        ));

        //Cache data for one day by default
        $cache = new File($frontCache, array(
            "cacheDir" => $config->application->cacheDir
        ));

        return $cache;
    });

    //Set up the flash service
    $di->set('flash', function() {
        return new \Phalcon\Flash\Session(array(
            'error'   => 'alert alert-danger',
            'success' => 'alert alert-success',
            'notice'  => 'alert alert-info',
        ));
    });

    /**
     * Start the session the first time some component request the session service
     */
    $di->set('session', function () {
        $session = new SessionAdapter();
        $session->start();

        return $session;
    });

}

在会话服务的声明中,使用依赖项注入方法“set”。我认为您需要使用“setShared”,因为这使会话服务充当一个单例,这将使您在其中设置的任何内容都可供其他控制器使用

我有这个确切的设置,它为我工作

我认为使用set方法会导致每次创建新会话,而不是提取包含数据的现有会话

    $di->setShared('session', function () {
        $session = new SessionAdapter();

        $session->start();

        return $session;
    });

我现在没有时间给你一个完整的答案,但你的问题是
session\u write\u close()
。删除这些呼叫。如果它解决了这个问题,我将发布一个详细的答案,以备将来参考reference@UlugToprak是的,但还是一样的问题。。请张贴完整答案。感谢您不需要调用
$this->session->start()start()
。@UlugToprak我已将其从代码中删除。问题仍然存在。。。