I need an example for command below in Symfony2 :
php app/console doctrine:mongodb:fixtures:load --fixtures=/path/to/fixture
I don't know how to set the --fixtures=/path/to/fixture. I can load all together but I cannot do it for only one new fixture !
What format should /path/to/fixture be ?
Also I tried this --fixtures=src/PMI/UserBundle/DataFixtures/ORM/FeatureFixtures but I get this every time :
[InvalidArgumentException]
Could not find any fixtures to load in:
- src/PMI/UserBundle/DataFixtures/ORM/FeatureFixtures
I know this is old but other people have asked and these answers may not cover some of the other questions.
You only need to specify the folder, not the file. In the above question, its not clear if FeatureFixtures is the php file or actually a folder. It may be failing if that is only a php file and not a folder. This is the correct way to load the fixtures assuming that FeatureFixtures is a php file with the fixtures:
doctrine:fixtures:load --fixtures=src/PMI/UserBundle/DataFixtures/ORM --append
You can define a fixture with the real path.
php app/console doctrine:fixtures:load --fixtures=src/MyBundle/DataFixtures/ORM/LoadMyFixturesData.php
It's not require but if you want to manually specify the directory where the fixtures classes should be loaded you can use this :
for example if I execute a command in directory symfony
--fixtures=/src/yourBundle/fixture
Starting with DoctrineFixturesBundle version 3.1 you need to use doctrine:fixtures:load --group=FeatureFixtures.
For symfony +3 you can use this command:
php bin/console doctrine:fixtures:load --group=YourFixtures --append.
Or short version:
php bin/console d:f:l --group=YourFixtures --append.
where option:
--group Target fixture. If you do not use the option, then load all your fixtures;
--append Without this option the load fixture command will remove all data from your database. Use this option to add new data without removing old data.
Related
I wanted to create an entity, basing on a database table. I followed these steps: Doctrine/Symfony entity generator and generating entity from one table , that is, in terminal:
php bin/console doctrine:mapping:import --force AppBundle yml --force --filter="Client"
php bin/console doctrine:mapping:convert annotation ./src/AppBundle/Entity --from-database --filter="Client"
php bin/console doctrine:generate:entities AppBundle:Client --no-backup
This created the entity "Client". But, it also created a client.orm.yml file in the src/AppBundle/Resources/config/doctrine directory. And this causes problems - that is, my application now crashes with an error message:
"No mapping file found named 'User.orm.yml' for class
'AppBundle\Entity\User'"
I think Symfony/Doctrine started using those yml files to map my php code to database schema. But why? I didn't want it. I just wanted Doctrine to create an entity.
p.s. When I remove this client.orm.yml file, everything works fine. But I don't understand what is happening, and how should I handle it properly.
You can delete these files after entity creation process. These files for metadata mapping.
You can read this
martinfowler.com/eaaCatalog/metadataMapping.html and martinfowler.com/eaaCatalog/dataMapper.html
Why doctrine does not delete ? Because, it is first step for convert process. Your first command creating those files after you command to doctrine and it is creating Entity files referenced with those files. :)
I am using symfony2 and doctrine and today using command
php app/console doctrine:schema:update --force
encountered the following error:
[Doctrine\Common\Persistence\Mapping\MappingException] Class
'AppBundle\Entity\Linkksiazkaokladka' does not exist
eventhough I had no Entity\Linkksiazkaokladka.php file.
I have also noticed that:
php app/console doctrine:generate:entities AppBundle
generates entities which are not available in /entity/ directory.
Make sure that your Resource/Config/Doctrine directory is clear.
It seems that Doctrine generates entities first of all based on data in this directory.
In my case clearing Resource/Config/Doctrine helped.
I'm trying to get the URL of my page with Twig.
So I wrote this in my index.html.twig:
{{ app.request.attributes.get("_route") }}
I'm getting this Symfony exception:
Variable "app" does not in exist in "AcmeFoo..."
I had the same problem and sometimes in addition to clearing the cache, it was necessary to rebuild the bootstrap cache. I created a little shell script (cache.sh) like this:
#!/bin/bash
cd /yoursymfonyrootfolder
php app/console cache:clear --env=prod
#path depends on symfony version
php ./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
Just place that file in your symfony root folder and execute it with ./cache.sh
I'm new to symfony and doctrine, so please correct me if I'm wrong.
If I run the command
php app/console doctrine:generate:entity
Doctrine creates an Entity with the given class name and the fields with the given types. Also it creates the mapping file.
Now what I would like is a command which creates only the mapping file.
Something like:
php app/console doctrine:generate:mapping
where doctrine creates only the mapping file on the class I wrote. Is that possible, how can I achieve that?
I don't understand fully what you need to do, in any case mapping files I guess could be generated only if read from an existent database or with a conversion of the mappings:
(in symfony) $ php app/console doctrine:mapping:convert
If you would like to use doctrine command it is in:
$ php vendor/doctrine/orm/bin/doctrine
But I never run this in a full stack symfony framework.
So I have an existing database but I was unable to follow the steps outlined here: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html because some of my tables have foreign keys for primary keys.
My solution has been to create a copy of the database without foreign key constraints and generate the .yaml files from THAT first.
So now I have XXX.orm.yml files in ./src/My/MainBundle/Resources/config/doctrine/metadata/orm
Next I tried to turn these .yml files into Entity classes with annotations by using this command:
php app/console doctrine:mapping:import MyMainBundle annotation
However that ignores my .yml files. It either generates the generic classes from my database without foreign keys, or it throws an error if I use it on my real database. It never even looks at my .yml files.
So all I want to know, is how can I transform the *.orm.yml files to Entities?
I'm not 100% sure if this is all I had to do to fix it, but I think the solution was as simple as moving my .orm.yml files from
./src/My/MainBundle/Resources/config/doctrine/metadata/orm
to
./src/My/MainBundle/Resources/config/doctrine
and running
php app/console doctrine:mapping:import MyMainBundle annotation --path="./src"
Use convert after import to convert yaml to entity annotations :
php bin/console doctrine:mapping:convert annotation src
See --help for further informations.
To force override entity files use --force option.
To create accessors (getters and setters) use
php bin/console doctrine:generate:entities yourBundle
Don't forget to check if yml files don't override behavior of annotation changes...
Regards
--path isn't an option to the command doctrine:mapping:import
after:
php bin/console doctrine:mapping:import YourBundle yml
use:
php bin/console doctrine:generate:entities YourBundle