cekurte / doctrinebundle
A extension of features of the doctrine library
Installs: 690
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
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-10-16 02:46:26 UTC
README
- An extension to Doctrine DBAL that can be used to switch between database connections in runtime with Symfony 2, contribute with this project!
If you liked of this library, give me a star =).
Installation
- The package is available on Packagist.
- The source files is PSR-2 compatible.
- Autoloading is PSR-4 compatible.
composer require cekurte/doctrinebundle
After, register the bundle in your AppKernel like this:
// app/AppKernel.php // ... public function registerBundles() { $bundles = array( // ... new Cekurte\DoctrineBundle\CekurteDoctrineBundle(), // ... ); // ... return $bundles; }
Documentation
Well, firstly you must configure a doctrine database connection. So, add this in your config file.
# 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"
After that, when you need change the database connection you can retrieve a service id named doctrine.dbal.dynamic_connection
and call the method forceSwitch
, see the example below.
<?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 ) ; } }
Contributing
- Give me a star =)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Make your changes
- Run the tests, adding new ones for your own code if necessary (
vendor/bin/phpunit
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request