blast-project / doctrine-session-bundle
通过 doctrine 将您的 Symfony 会话存储到数据库中
0.6.4
2017-11-03 14:58 UTC
Requires
- php: >=7.1
- doctrine/doctrine-bundle: >=1.6
- symfony/symfony: >=3.2
Requires (Dev)
- blast-project/core-bundle: 0.6.4
- blast-project/tests-bundle: 0.6.4
- phpunit/phpunit: ^6.4
- sonata-project/doctrine-orm-admin-bundle: >=3.1
- symfony/console: >=3.2
- symfony/phpunit-bridge: >=3.2
Suggests
- blast-project/core-bundle: Define sonata admins in yml and more
This package is not auto-updated.
Last update: 2024-09-14 20:40:47 UTC
README
该扩展包的目标是使 Doctrine 成为 Symfony 的会话处理器
安装
下载
$ composer require blast-project/doctrine-session-bundle
添加到您的 AppKernel
//... class AppKernel extends Kernel { public function registerBundles() { $bundles = [ //... new Blast\DoctrineSessionBundle\BlastDoctrineSessionBundle(), ]; //... } //... }
Doctrine
配置您的 Doctrine 连接
# app/config/config.yml doctrine: dbal: default_connection: default connections: default: driver: pdo_pgsql host: "%database_host%" port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" charset: UTF8 session: # This will be the connection used by this bundle driver: pdo_pgsql host: "%database_host%" # Please adapt to your needs if you're using another database for sessions port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" charset: UTF8 orm: default_entity_manager: default auto_generate_proxy_classes: "%kernel.debug%" entity_managers: default: connection: default naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true mappings: # Add here your mapping for your default entities # Example below : BlastBaseEntitiesBundle: type: yml session: connection: session naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: false # Only one entity manager can have auto_mappping set to true mappings: BlastDoctrineSessionBundle: type: yml
配置框架会话处理器
# app/config/config.yml framework: # [...] session: handler_id: blast_doctrine_handler
数据库
$ php bin/console doctrine:database:create --connection=session
或者
$ php bin/console doctrine:schema:update --force --connection=session
使用方法
use Blast\DoctrineSessionBundle\Handler\DoctrineORMHandler; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; //... $doctrinehandler = new DoctrineORMHandler( $this->get('doctrine'), 'Blast\DoctrineSessionBundle\Entity\Session'); $storage = new NativeSessionStorage( array(), $doctrinehandler ); $session = new Session($storage); $session->start(); //...
参见
https://symfony.ac.cn/doc/current/components/http_foundation/session_configuration.html