Symfony Gedmo Translatable and YAML configuration for generating entities - symfony

is it possible to use in a Symfony project Gedmo Doctrine Extension Translatable with YAML configuration and to generate the entities with php bin/console doctrine:generate:entities ?
I tried the StofDoctrineExtensionsBundle, I tried Gedmo on its own. But I didn't get it working.
When I write the entities by hand and use annotations everything works fine. But in my project every entity is defined by YAML.

Related

Symfony 4 getter setter not generated from existing database

I know that to generate entity from existing database in symfony 4, just execute this command :
> php bin/console doctrine:generate:entities
but this command dont generate getter setter, just generate variable from column.
and of course I must use some dirty work to create it manually.
may be I missed read the documentation, how to generate entities getter setter from existing database using doctrine symfony 4?
To generate entity classes from an existing database you need to ask Doctrine to introspect the database and generate the corresponding metadata files. Metadata files describe the entity class to generate based on table fields.
> php bin/console doctrine:mapping:import App\\Entity annotation --path=src/Entity
This command will generate new PHP classes with annotation metadata into src/Entity
To generate the missing getter/setter methods (or to create the classes if neceesary), run:
> php bin/console make:entity --regenerate App
Also check Official documentation
DOC says:
"If you prefer to add new properties manually, the make:entity command can generate the getter & setter methods for you:
php bin/console make:entity --regenerate
If you make some changes and want to regenerate all getter/setter methods, also pass --overwrite."
Also note that with Symfony 3 (I don't about v4), the doctrine:generate:entities did not work with protected properties
To do that from an existing database you can use reverse engineering. Follow these steps:
configure your database in .env file
2.1. create the entity from your configured database with:
php bin/console doctrine:mapping:convert --from-database annotation ./src/Entity
2.2. if you want create the entity for one specific table:
php bin/console doctrine:mapping:convert --from-database --filter="Tablename" annotation ./src/Entity
if you use vim, you can add getters and setters installing php-getter-setter.vim plugin and typing in each entity:
:% InsertBothGetterSetter
you must add manually in each entity:
namespace App\Entity;

Symfony 4, a way for generate Entities from an Existing Database?

With Symfony 3 and its console, we can generate entities from an already existing database via the command "php bin/console doctrine:mapping:import" (very usefull !).
From symfony 4, the command "./bin/console doctrine:mapping:import" needs a bundle name but symfony 4 doesn't work with bundle now.
With the new version of symfony, is there a way I didn't see for generate entities from an existing Database (mysql by example) ? Or must I wait a new version of doctrine for have a "doctrine:mapping:import" compatible with Symfony 4 ?
I found a(n) (ugly) solution yet. I deploy a disposable symfony 3, I link the symfony 3 to my database and I generate entities in a bundle. Then I copy generates files to symfony 4.
It's ugly but it works haha
You can use
php bin/console doctrine:mapping:convert --from-database annotation ./src/Entity
which should create the entities based on the database setting. Don’t forget to add the namespaces, and you will still need to add the getters and setters, but the bulk of the properties, including annotations and some of the relationships are already included. (Source)
Please also note, that Doctrine will not support this anymore in the next Doctrine version. As written in the Symfony docs
Moreover, this feature to generate entities from existing databases will be completely removed in the next Doctrine version.

Gedmo Doctrine Extensions and YML

I am trying to configure translatable extension in my own project. The problem is that I have a whole bundle configured using yaml for mapping entities, so each entity have its own .orm.yml file. Now, I am trying to add the translatable extension but when I run the schema update command I get:
No identifier/primary key specified for Entity "Ruck\SportsBundle\Entity\Tr anslation\SportTranslation" sub class of "Sonata\TranslationBundle\Model\Ge dmo\AbstractPersonalTranslation". Every Entity must have an identifier/prim ary key.
In other bundle where I have used annotations it works fine... So my question is if translatable extension is incompatible with yaml files.
I have reading about this issue
https://github.com/Atlantic18/DoctrineExtensions/issues/671
https://github.com/Atlantic18/DoctrineExtensions/issues/989
but I think is too strange that I can't use yml files with translatable extension...
Thanks

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?

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