Setup symfony CMF - symfony

I want to start with Symfony CMF, but I have a problem. I followed tutorial but instead of using default SQL, I need MySQL with doctrine ORM, so I tried configuring it following these guides. Everything looks good until I try to initiate database, by using following command using Doctrine ORM:
$ php app/console doctrine:database:create
$ php app/console doctrine:schema:create
but after firing
$ php app/console doctrine:schema:create
I get error: "No Metadata Classes to process."
As far as my conclusion goes, I need to create some classes which will act as routes, though nothing of that sort is mentioned in above guides. To avoid long post I setup git repo with source code. What may be the cause of this problem, and how could I fix it?

From your repository, it seems you did not configure doctrine orm at all. you are referencing the setup guides for phpcr-odm and your sandbox is configured to use phpcr-odm. you can use jackalope-doctrine-dbal to use phpcr-odm with mysql.
if you really want to use the cmf with doctrine orm, only the RoutingBundle provides entities out of the box, and you will need to adjust those to suit your project.

Related

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.

How to generate basic CRUD in Symfony2

I'm new in Symfony and I was wondering if there is a way to generate basic CRUD elements for database, preferably with Bootstrap 3. Other frameworks (Laravel, CakePHP) set you off with a functional application.
The best bundle IMHO is EasyAdminBundle by Javier Eguiluz.
But you can also look at AdminGeneratorBundle and SonataAdminBundle
All of these bundles use Bootstrap.
By default the command is run in the interactive mode and asks questions to determine the entity name, the route prefix or whether or not to generate write actions:
php app/console generate:doctrine:crud
To deactivate the interactive mode, use the --no-interaction option but don't forget to pass all needed options:
php app/console generate:doctrine:crud --entity=AcmeBlogBundle:Post --format=annotation --with-write --no-interaction

Symfony, how to keep the declaration of entities repository after re-import my table

The structure of the database I am using for my project is constantly changed by another team. So I have to import regularly this structure into Symfony. To do so I use the following command:
php app/console doctrine:mapping:import --force EgBundle yml [--filter="Table"]
php app/console doctrine:generate:entities [Company/EgBundle/Entity/Table]
Every time I run those command I loose the declaration of my repositories and I have to had them manually:
repositoryClass: Company\EgBundle\Entity\TableRepository
Is there any way to keep this declaration?
There is no way for Doctrine to know what the repository class shall be when importing a mapping from database. The information can't be obtained from the database schema.
A possible solution for your use-case would be extending\overriding the doctrine:mapping:import command to add a Repository to the mapping information automatically using a naming convention.

Symfony Doctrine Mapping:Import & Table Association

I am working with Symfony 2.3 on a new project using an existing database with numerous associations - many-to-many, one-to-many etc. During my initial import last week, I found somewhere in the docs stipulated that a doctrine:mapping:import would generate orm.yml files of my database which it did without a hitch. However, I also see that only ManytoOne relationships are generated in the yml files ... not any other kind of associations.
My statement was:
$ php app/console doctrine:mapping:import –em=buv DBImportTestBundle yml
Also, I did a generate entities to create classes and basic CRUD for each table using:
$ php app/console doctrine:generate:entities DBImportTestBundle
This also worked EXCEPT that I do not see any annotated associations generated in the doc blocks for any of the entity properties.
I'm looking through the docs but do not see any specific information on the exact requirements for associations on imported dbs. It could be I'm not looking in the right place.
I'm trying to determine the most efficient way to maintain my db schema within symfony/doctrine ... My understanding was that I would need to explicitly define certain associations manually but I'm not sure what the exact requirements would be OR if perhaps I'm simply not passing in the correct arguments to create my annotated associations via generate:entities.
Can someone point me to any docs that refer to what I'm talking about or explain the proper approach to defining complex associations within doctrine? Thank you.
$ php app/console doctrine:mapping:convert annotation ./src to generate entity classes with annotation mappings, before running :
$ php app/console doctrine:generate:entities DBImportTestBundle
there is a cookbook for that

Manually editing and deleting an entity - Symfony2

How do I manually edit and delete an entity in Symfony2?
I get that it creates a class, but how do I edit everything? I'm guessing I can't just change the PHP class file.
So which files does it create when you use the automatic entity generator and is there an automated-edit command? I use Yaml.
I know with bundles then you there are three files that the automated console command creates/changes, but I can't see any info as to how for entities.
I like to use the automation to save time, but still like to know actually what is being done etc.
Modify your php code ( Entities code ) then just run
php app/console doctrine:generate:entities BundleName:EntityName
you may also want to update your db by running
php app/console doctrine:schema:update --force

Resources