Symfony2 and Doctrine2 multiple database example
For more information on this repo please see my article on using multiple databases with Symfony2 here:
How to setup
- Clone the project: git clone firstname.lastname@example.org:lobsterdore/symfony2-multiple-db-example.git
- Download composer into the root of the project if needed: curl -s https://getcomposer.org/installer | php
- Setup permissions on cache and logs directory as shown in the Symfony2 docs: http://symfony.com/doc/current/book/installation.html#configuration-and-setup
- Run composer update to install the various third party libraries needed
- Create the two test databases 'symfonydemo_post' and 'symfonydemo_user';
- You can build the databases automatically, simply set the db name in parameters.yml to 'symfonydemo_post' and run 'php app/console doctrine:schema:update' to create the tables, change the db name to 'symfonydemo_user' and repeat the process to build the tables for the User entity.
How to use
Once everything is setup navigation to '/users', from here you can use the autogenerated CRUD interface to add a user.
If you navigate to '/posts' you can add a new post with a user relation, the form can update the relation seamlessly. On the index page you will also see that the username associated with the post is outputted just as any other relation.