Import DateTime using the Nemo / Alice package

My question is about this bundle: https://github.com/nelmio/alice combined with Symfony2.

I have some device that I want to download on my new website, and this kit is great for this. I created some YML files and viewed the following YML as my file:

DateTime (local): news-date-1: __construct: ['2014-07-01'] Stef\BVBundle\Entity\Blog: StefBVBundle-Blog-1: title: 'A day with blah' blog: 'e5645646' image: 'beach.jpg' author: 'dsyph3r' tags: 'symfony2, php, paradise, symblog' created: @news-date-1 updated: @news-date-1 StefBVBundle-Blog-2: id: 1 title: 'meeeh' author: dsyph3r blog: '5rw5425' image: beach.jpg tags: 'symfony2, php, paradise, symblog' created: '2014-07-01T00:00:00+0200' updated: '2014-07-01T00:00:00+0200' 

The one that is marked as "StefBVBundle-Blog-1" works like a charm; he knows that he "created" and "updated" the \ DateTime values.

But "StefBVBundle-Blog-2" causes an error because the Nemo / Alice package treats it as a string, not a DateTime. Is it possible to make a built-in DateTime part?

+5
source share
2 answers

PHP expressions inside <()> are just passed in to Doctrine, so this will do the job:

 Stef\BVBundle\Entity\Blog: StefBVBundle-Blog-2: created: <(new \DateTime('2014-02-02'))> 
+19
source

As for the Faker doc, you need to specify an instance of DateTime or DateTimeBetween without time laps if you want an exact date.

Your fix code is:

 DateTime (local): news-date-1: __construct: ['2014-07-01'] Stef\BVBundle\Entity\Blog: StefBVBundle-Blog-1: title: 'A day with blah' blog: 'e5645646' image: 'beach.jpg' author: 'dsyph3r' tags: 'symfony2, php, paradise, symblog' created: @news-date-1 updated: @news-date-1 StefBVBundle-Blog-2: id: 1 title: 'meeeh' author: dsyph3r blog: '5rw5425' image: beach.jpg tags: 'symfony2, php, paradise, symblog' created: <dateTimeBetween('0 days', '2014-07-01T00:00:00+0200')> updated: <dateTimeBetween('0 days', '2014-07-01T00:00:00+0200')> 

Not tried, but should work.

+3
source

Source: https://habr.com/ru/post/1200771/


All Articles