Symfony2 environment specific doctrine mappings configuration - symfony

I've got a test bundle which has some doctrine entities. In AppKernel I added this bundle only to the dev and test environments and also made the mapping definitions for doctrine in the config.yml. The problem is in prod environment doctrine can't find the entities as the bundle isn't loaded in kernel. I don't want to load the test bundle in prod env.
I also have other entities defined in different bundles for doctrine so I'd switch the test bundle off in the config_prod.yml or set it to null - is it possible somehow? I don't want to copy and redefine the whole mappings array/list in config_prod.yml.

Related

Can Symfony Bundle be used in non-Symfony project (f.e. Zend)?

Can I reuse my Bundle created in Symfony in non-Symfony project, f.e. Zend? (Or I only can reuse Components?)
What about services from that Bundle?
A Symfony bundle can certainly be included in with other projects, via a composer.json & composer.lock file - it doesn't mean that there is any useful code to run within that bundle however.
If there is useful code as part of the bundle, then you can use it directly, but a Symfony Bundle is just a library that will usually include some Symfony-specific configuration.
Best practice for a bundle is to put any useful, common code, into a separate library (which could be used independently - such as what Symfony calls a 'Component'), and then enable that code (for example creating Symfony services, or configuration) with the bundle configuration.
There have been projects that are Symfony bundles, and also have the configurations for other frameworks as well, such as Silex, and also appropriate Laravel configurations within the same codebase.

How to use variables in Symfony Doctrine ORM annotations?

In short, I would like to use something like:
#ORM\Table(name="schemaname.tablename")
but replacing the "schemaname" string with a variable, that can be set as a configuration parameter somewhere (like in parameters.yml file)
I understand your context as a reusable bundle entity with cross domain relation to an other bundle.
I don't find anything about doctrine mapping customisation, but as your bundle can only be included once per project, I recommand you to use your bundle name as a prefix for the table.
Like yourapp_tablename
For the crossdomain constraint, your bundle, if it is reusable can't have dependencies to external bundles. It is your business bundles which have to use the reusable bundle, not the way around. I guess you have to use interfaces if you want an external bundle to be extending your model class

How to have advanced doctrine configuration in Symfony?

Reading these docs:
Doctrine DBAL Configuration with Symfony
Doctrine ORM Configuration with Symfony
Doctrine Configuration with Symfony
I created this and added to /src/MyBundle/Resources/config/services.php of my generated bundle:
My Configuration code
But I get the error:
[Symfony\Component\DependencyInjection\Exception\LogicException]
Container extension "doctrine" is not registered
What more I missed to do? I probably have to add that I did NOT remove the default orm/dbal settings in /app/config/config.yml.
Also I have no idea what 'read' and what 'host'=>'from_user_config.db' is, I copied/pasted from a third-party application and how to inject db credentials from a separate file into this services.php?

Location of propel.ini for symfony2?

I am migrating from symfony1 to symfony2, I have hard time implementing propel behaviors. Where do I actually have the propel.ini in symfony2?
Well in sf1.4, it was inside root config directory. How about symfony2?
The Propel ORM Symfony2 page says this:
You can add a app/config/propel.ini file in your project to specify some configuration parameters. ... However, the recommended way to configure Propel is to rely on build properties.
You can define build properties by creating a propel.ini file in app/config like below, but you can also follow the Symfony2 convention by adding build properties in app/config/config.yml
So I believe you can come close to the Symfony1 behaviour by creating app/config/propel.ini, but the more idiomatic way is to use app/config/config.yml as that page illustrates.
Caveat: I haven't used Propel with Symfony2, so this answer is solely based on the manual.

Multi-Bundles in Symfony 2

I create project from Symfony 2, but I have a problem:
In project have multi-bundles(ex: AdminBundle and FontEndBundle)
Case 1: Doctrine orm and Entities generate on FrontEndBundle, then from AdminBundle, I will call Entity via FrontEndBundle:Object it work OK.
Case 2: I want to config structure folow
src/Project/
Model/Entity
OrmYml/doctrine/orm
Bundles(contains FontEndBundle & AdminBundle)
Extensions
In case 2, How do I config Entity mapping to generate Entities to src/Model/Entity directory ? Because when I using Command: doctrine:generate:entities Project/Model/Entity,
error : Namespace "Project\Model\Entity" does not contain any mapped
entities.
How do you declare your entities ?You should put your entities within a bundle. You cant have them outside a bundle .
Usually, Symfony developpers create a third bundle called "CoreBundle" (for example) where you place all the shared resource between your three bundles, namely the entities, some services (like twig extensions), config (with service.xml/yml), ... Also, you can delete the controller and views directories in this bundles, which are useless (don't forget to clean the app/config/routing.yml file by removing the CoreBundle controller injection) !
Then just call your entities in the right bundle with:
use MyName\Bundle\CoreBundle\Entity\MyEntity;
Never create a model repertory not in a bundle, this is not the Symfony philosophy and you are really wrong !

Resources