
Powered by Vanilla 1.1.5a.
Installed add-ons.
Buy iPad online
at PC World.Recently Lolly asked me to help him with an intranet application, which I thought immediately, "Symfony is the thing for that".
I then noticed that there is a (not quite so) new version, Symfony 1.4.1, which has several differences to the previous versions.
The most noticeable difference is the choice of Doctrine rather than Propel for database abstraction.
I have found that the documentation for Propel for my last experiments has been rather good, with a very useful schema cheat-sheet (http://andreiabohner.wordpress.com/2007/09/01/symfony-cheat-sheet-schema/). Doctrine, however, has been lacking in API documentation.
I have investigated the doctrine behaviours in the configuration, notably the "Timestampable" behaviour which should behave (as documented) by adding "created_at" and "updated_at" columns, which should do the obvious thing.
Test Schema:
Test:
actAs: [Timestampable]
columns:
name: string(255)
I then generated an application from my model, and I was stumped.
For some reason, as the model now includes these 2 fields, they're required when creating new objects when being validated. If you then put in information that's not the current date/time, it will set it to them, rather than the actual values they should be.
After much huffing and puffing I have now worked out the solution; which is almost understandable, if very annoying.
Doctrine and Symfony assume that you might want to be able to manually edit the created_at or updated_at fields, so you can lie about these things. In order to get the expected behaviour I needed to make some changes:
unset($this->widgetSchema['created_at']);
unset($this->validatorSchema['created_at']);
unset($this->widgetSchema['updated_at']);
unset($this->validatorSchema['updated_at']);
This then removes the widgets from the form (so I don't have to see them!
) and then tells it that they're not required to be validated.
Now it works with the expected behaviour,
When I create a new entry, the created_at and updated_at are now at the correct times, and when I edit it, the updated_at updates without any extra magic.
I just wish someone had put this information in an easy to find place so I knew why it wasn't doing what it told me it'd do! ![]()
Nice
Nice
A faster way of doing it
unset(
$this['created_at'], $this['updated_at']
);
![]()
Nice Beanz ![]()
1 to 5 of 5