I get that it saves into PHPCR through Doctrine ODM.
But I get that it is all saved in app.sqlite, but I don't see how does it works conceptually ?
Why does it need the database at all when everything is saved in app.sqlite?
Why do I need to make this kind of commands php app/console doctrine:phpcr:init:dbal and so on ?
Symfony CMF can work with different model classes. we provide a default implementation that is mapped for Doctrine PHPCR-ODM. PHPCR-ODM in turn is built on the php content repository PHPCR. there are 3 implementations of that, the cmf sandbox by default uses jackalope-doctrine-dbal. jackalope-doctrine-dbal in turn uses doctrine dbal to store content into databases supported by doctrine dbal. jackalope currently handles sqlite, mysql and postgres. jackalope-doctrine-dbal needs some initialization on the first run, which are the commands you have seen. this is the same whether we use the embedded sqlite database driver or mysql or postgres.
You find some background for the choices in choosing a storage layer and information how to set up phpcr-odm in Create a New Project with PHPCR-ODM. Look around at http://symfony.com/doc/master/cmf/index.html to have most of the CMF concepts and implementation explained.
Related
Is there a way to define the complete database schema in one go in Symfony 4?
I understand that individual entities/objects can be created using the make:entity and make:migration commands but I'm wondering if I could just define the entire schema in one sitting and then use it to build the associated entities and database.
I recall that in earlier versions of Symfony it was possible to define the entire schema in a YAML file and then just issue a build command.
Yes, you can create complete database schema mappings using any of supported mapping formats (e.g. YAML or XML) and declare mappings location in Doctrine configuration. After that you will be able to use any Doctrine console tools to generate and update schema. You can also use tools for reverse engineering mappings from already available database and to convert mappings between formats
Please notice that Doctrine commands names in Symfony application are different from ones that natively provided by Doctrine. You need to use:
doctrine:schema:validate for schema validation
doctrine:schema:create for initial schema generation with subsequent calls of doctrine:schema:update with either --dump-sql or --force depending on your needs
doctrine:mapping:convert to reverse engineer available database (with use of --from-database option) or convert between mapping types in a case if you want to.
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.
I am a new developer on an existing php project that respect its proper mvc.
I have successfully "plug" a Symfony installation on it, in order to replace some of the already existing Symfony components such as Router, Request etc...
I have some functionalities to develop and I am isolating them under one bundle.
My question is : can I use Doctrine for this one in order to start a sanitize work on the existing database ? If I want to use foreign keys with the existing others tables I need to configure the mapping on them...It's a problem because I cannot start a refactoring for the objects of this project that are not entities-like. Is there a solution to use doctrine only for my bundle and keeping the use of foreign-keys, cascading etc... ?
Thank you for all
If you wish to only generate the entities for your isolated bundle, you can do it.
Check documentation: http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_doctrine_entity.html
Are you planning to create your tables in the same database or in a differente database?
I'm working on a SF2 project where I can't use Doctrine2 as ORM, meaning that I already have a database with tables and data. I have to use plain SQL in my controller (I'm currently using DBAL to do that), and I have to create object in order to represent things.
When I used to work with Doctrine2, I create Entity by app/console doctrine:generate:entity and Doctrine2 is handling the whole stuff (update, persisting...)
But now, as I'm using DBAL, how can I create object (can I call it entity even if i'm not using ORM?) to fit my need ?
I was planning to do like usual : create an entity folder in my bundle with entities as objects without the ORM annotations, and create a method where I retrieve data from database using SQL (result of the query in an array) and hydrating it using getters/setters from the object.
Is it a good idea or do you have a better solution ? I'm beginning with SF2 and I read that some people create a service to retrieve data and then using data transformer to transform data into the object.
Thank you.
You are describing Active Record pattern. For this purpose you can use Propel that has native integration with Symfony. Read about it on Symfony's official documentation.
Also I would recommend you to use ORM. You can set your mapping with existing tables as you want: you can even omit some fields if you don't need them in entity. And Doctrine ORM will do all the hard work for you.
You can still use ORM without changing your database by creating classes from your database. You should read this in the symfony documentation
Is there any chance I can migrate only one database, if I have define multiple connections in my config.yml
If I run
propel:migration:diff --connection=a it still want to generate migration for all databases defined.
My vendors
propel/propel-bundle 1.2.7 Integration of Propel in Symfony2
propel/propel1 1.6.9 Propel is an open-source Object-Relational Mapping (ORM) for PHP5.
Yes, you can. Although I have Propel 1.7.1 I don't think this has changed since 1.6.9.
You have to create a separate buildtime-conf.xml file for each connection and then pass the path to this file while calling propel-gen diff. So, let's say you have a-buildtime-conf.xml:
propel-gen . diff -Dpropel.buildtime.conf.file=a-buildtime-conf.xml
I found this by debugging the GeneratorConfig::getBuildConnections() method.