craffft/single-session-storage-bundle

为 Symfony 的 SingleSessionStorageBundle

1.3.1 2020-04-14 19:32 UTC

This package is auto-updated.

Last update: 2024-09-15 05:23:30 UTC


README

Build Status

单会话存储包

为 Symfony 的单会话存储

安装

步骤 1: 下载包

打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

$ composer require craffft/single-session-storage-bundle "~1.1"

此命令要求您已全局安装 Composer,具体请参阅 Composer 文档中的安装章节

步骤 2: 启用包

然后,通过将其添加到项目 app/AppKernel.php 文件中注册的包列表来启用此包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Craffft\SingleSessionStorageBundle\CraffftSingleSessionStorageBundle(),
        );

        // ...
    }

    // ...
}

使用示例

<?php
// AppBundle/Controller/DemoController.php

// ...
class DemoController extends Controller
{
    public function myAction()
    {
        // Set data via service
        $singleSessionStorage = $this->container->get('craffft.single_session_storage');
        $singleSessionStorage->setNamespace('testStorage'); // optional
        $singleSessionStorage->set('key', 'value');
        $singleSessionStorage->saveSession();
        
        // Set data via class
        $singleSessionStorage = new SingleSessionStorage($this->container, 'testStorage');
        $singleSessionStorage->set('key', 'value');
        $singleSessionStorage->saveSession();
        
        // ...
    }

    // ...
}