Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import DateTime using Nemo/Alice bundle

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

I have some fixture i want to load in my new website, and this bundle is great for that. I created some YML files and consider the following YML as my fixturedata:

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 labelled with 'StefBVBundle-Blog-1' works like a charm, it knows 'created' and 'updated' are \DateTime values.

But 'StefBVBundle-Blog-2' causes an error, because the Nemo/Alice bundle consider it as a string, instead of a DateTime. Is it possible to do the DateTime-part inline?

like image 696
Stefanius Avatar asked Aug 20 '14 16:08

Stefanius


Video Answer


1 Answers

PHP Expressions inside <( )> are simply passed to Doctrine, so this will do the work :

Stef\BVBundle\Entity\Blog:
    StefBVBundle-Blog-2:
        created: <(new \DateTime('2014-02-02'))>
like image 162
Paul Mallet Avatar answered Sep 28 '22 01:09

Paul Mallet