Skip to main content
100%

Gist 073f04cf10ae55fafc00

✓ Published0🌍 Public
Aallyraza
Last edited Aug 16, 2012
Created on Mar 18, 2015

This example demonstrates a Yii PHP behavior that automatically formats and parses date fields in Active Record models, as seen with the `Person` model's `birthdate` and `last_checkin` attributes. The `DateFormatterBehavior` class intercepts the `beforeSave` event to convert timestamps into formatted date strings and parse user input back into timestamps using `CDateTimeParser`. It also provides a `checkDate` validation method, invoked via a model rule, to ensure date correctness. Configuration defines date formats like `short` as `d/M/yyyy`, with helper functions `df` and `parse_date` bridging Yii’s date formatter.

AI-generated description

Similar vizzes