概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:41:41 | 119 次阅读 | 评论: 0 | 来源: 网络整理

2.3 新版功能: The ability to integrate with a legacy PHP session was introduced in Symfony 2.3.

If you’re integrating the Symfony full-stack Framework into a legacy application that starts the session with session_start(), you may still be able to use Symfony’s session management by using the PHP Bridge session.

If the application has sets it’s own PHP save handler, you can specify null for the handler_id:

  • YAML
    framework:
        session:
            storage_id: session.storage.php_bridge
            handler_id: ~
    
  • XML
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services"
        xmlns:framework="http://symfony.com/schema/dic/symfony">
    
        <framework:config>
            <framework:session storage-id="session.storage.php_bridge"
                handler-id="null"
            />
        </framework:config>
    </container>
    
  • PHP
    $container->loadFromExtension('framework', array(
        'session' => array(
            'storage_id' => 'session.storage.php_bridge',
            'handler_id' => null,
    ));
    

Otherwise, if the problem is simply that you cannot avoid the application starting the session with session_start(), you can still make use of a Symfony based session save handler by specifying the save handler as in the example below:

  • YAML
    framework:
        session:
            storage_id: session.storage.php_bridge
            handler_id: session.handler.native_file
    
  • XML
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services"
        xmlns:framework="http://symfony.com/schema/dic/symfony">
    
        <framework:config>
            <framework:session storage-id="session.storage.php_bridge"
                handler-id="session.storage.native_file"
            />
        </framework:config>
    </container>
    
  • PHP
    $container->loadFromExtension('framework', array(
        'session' => array(
            'storage_id' => 'session.storage.php_bridge',
            'handler_id' => 'session.storage.native_file',
    ));
    

注解

If the legacy application requires its own session save-handler, do not override this. Instead set handler_id: ~. Note that a save handler cannot be changed once the session has been started. If the application starts the session before Symfony is initialized, the save-handler will have already been set. In this case, you will need handler_id: ~. Only override the save-handler if you are sure the legacy application can use the Symfony save-handler without side effects and that the session has not been started before Symfony is initialized.

For more details, see Integrating with Legacy Sessions.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务