how to use only annotation mapping in doctrine 2 - symfony

-Is there a way to make doctrine neglect or don't look in entityxx.orm.xml mapping files and look only in annotation mapping in the entity class?
-I'm getting error when try to modify an entity without modifying it's underline xml mapping too so i have to modify both!,actually my entities was imported from database but now it's converted to annotation and i don't want to use xml any more .

it's impossible to use 2 differents method mapping for entity in symfony. Xml or annotation but not both in the same time.
You must delete xml mapping file if you want to use a annotation mapping.

Related

override mapping for a specific Entity class

I'm using a standard Symfony 2.8 framework with Doctrine.
My entities' mappings are all annotated, but I would need to map a single entity by using the PHP way (by defining loadMetadata static method) . I know there's a way to override a mapping Bundle configuration like explained here, but what I would like is specifying a single Entity. Is that possible? Thanks
No you can't mix the formats
A bundle can accept only one metadata definition format. For example, it's not possible to mix YAML metadata definitions with annotated PHP entity class definitions.
see doc here:
http://symfony.com/doc/current/doctrine.html
if you really need to change the mapping format then I suggest you create a new bundle for your specific entity. I also had this problem. I wished to have different mapping format (yml and annotation in my case) but I had to create a new bundle.

Symfony 2.3 messages to user saved as resource yml file

Is there a way in Symfony 2.3 to use messages loaded from yml file?
Example: CRUD controllers echo a message just for having an entity created or not as Entity created..
Is there a way to define this string in a yml file and use it for every CRUD controller / Twig template and define it once and not to write it for every crud?
Explaining with a better example:
When an entity is created:
$this->get('session')->getFlashBag()->add('success-close', 'Entity created.');
But I just like to use something like this:
$this->get('session')->getFlashBag()->add('success-close', $str_entity_created);
where $str_entity_creted is defined in a hypothetic messages.ymlfile
#MyBundle/Resources/messages.yml
messages:
str_entity_created: "Entity created."
...
....
So, for every CRUD I have to change the string in just one place and it has changed globally in my entire app, instead of changing every string in every CRUD Controller.
Is there a way to accomplish that?
If I have to load a yml resource globally, how much will it degrade memory consumption and performance?
Use translations
$translated = $this->get('translator')->trans('Symfony2 is great');
messages.fr.yml
Symfony2 is great: J'aime Symfony2

Doctrine 2 base entities like those in doctrine 1?

I'm starting a new project with Symfony2/Doctrine2 and I generated my entities from the DB with the mapping:convert and mapping:import commands.
My entities are fine, but I only have the generated entities. Back in Doctrine1/Symfony1, you had your entities generated twice : once in the doctrine folder, an almost empty class just extending the second one in doctrine/base folder where all the doctrine internals were (getters/setters, fields...)
This way, you could add your own methods in the first file where they remained untouched even if you generated again the entities (only the doctrine/base files were modified by the generator).
Am I missing something ?
Well the generate command only generates getters and setters that are undefined and appends them to the (entity) file. This means that your custom getters/setters will never be overwritten. Does that answer your question?

PHP Composite Design Pattern with Symfony2 and Doctrine

Is there any example for Composite Pattern with Doctrine? I mean PHP source code using Doctrine annotations.
I could find Decorator Pattern here : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/decorator-pattern.html but no luck about Composite Pattern.
You should be able to do this with Inheritance Mapping (see http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/inheritance-mapping.html) and just normal associations with the type you want (see http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html)

Configurable parameters in Symfony2 entity annotation

I'm trying to create a join across multiple databases (one of them belonging to a legacy application) as described in the Doctrine blog. However, the example suggests hardcoding the name of the database right into the schema, which I'd like to avoid for obvious reasons.
Is there a way to read parameters defined in parameters.ini or config.yml and use them as a value for the annotations, like this?
/**
* #ORM\Table(name="%legacy_db_name%.%legacy_table_name%")
*/
No, it's impossible. The "%key%" form is only available in the DIC.
Why would you put these data in a yml file? Would it be useful?

Resources