cekurte / doctrinebundle
扩展 Doctrine 库的功能
v1.0.1
2016-05-03 19:45 UTC
Requires
- php: >=5.4
- doctrine/orm: ~2.4
- gedmo/doctrine-extensions: ~2.4
- symfony/framework-bundle: ~2.3
Requires (Dev)
- fabpot/php-cs-fixer: *
- phpunit/phpunit: ~4.5
This package is auto-updated.
Last update: 2024-09-16 02:40:23 UTC
README
- Doctrine DBAL 的扩展,可用于在运行时使用 Symfony 2 在数据库连接之间切换,为此项目贡献力量!
如果你喜欢这个库,请给我一个 星标 =)。
安装
composer require cekurte/doctrinebundle
然后,像这样在您的 AppKernel 中注册该组件:
// app/AppKernel.php // ... public function registerBundles() { $bundles = array( // ... new Cekurte\DoctrineBundle\CekurteDoctrineBundle(), // ... ); // ... return $bundles; }
文档
首先,您必须配置 doctrine 数据库连接。因此,在您的配置文件中添加以下内容。
# app/config/config.yml # ... doctrine: dbal: default_connection: dynamic connections: dynamic: driver: "%database_driver%" host: "%database_host%" port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" charset: UTF8 wrapper_class: "Cekurte\DoctrineBundle\DBAL\ConnectionWrapper"
之后,当您需要更改数据库连接时,可以检索一个名为 doctrine.dbal.dynamic_connection
的服务 ID 并调用 forceSwitch
方法,以下是一个示例。
<?php namespace YourNamespace\YourBundleBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class YourController extends Controller { public function indexAction() { // ... // Change the current database connection... $this ->get('doctrine.dbal.dynamic_connection') ->forceSwitch( $dbHost, $dbName, $dbUser, $dbPassword, $dbOptions ) ; } }
贡献力量
- 给我一个星标 =)
- 分支它
- 创建您的功能分支(
git checkout -b my-new-feature
) - 进行更改
- 运行测试,如果需要,为您的代码添加新的测试(
vendor/bin/phpunit
) - 提交您的更改(
git commit -am '添加了一些功能'
) - 推送到分支(
git push origin my-new-feature
) - 创建新的拉取请求