I like and want to use the typing observer such that things are properly typed when json formatted and returned to clients/languages that demand strict typing of variables.
I also have the need to properly display to the user certain properties that have to be formatted correctly for display. Examples are:
-date fields -currency related -select/radio/multi-selects
I have a custom observer I use to format and un-format properties before_save and after_load. For the most part this works fine when defined before the typing observer in my base model, with the exception of the created_at field.
Am thinking of ways to support both typing and display formatting together. One way I was thinking of was to add a <property>_display property for each property that needed to be changed/formatted for proper user display, then at render time it would show the _display property if it exists?
Anyone else run into these needs, if so how do you solve it?
Not exactly sure what the problem is, havent dug to deep yet.., this is the behavior I am seeing on the field though:
-I have all my date fields as data_type 'int' -I have my custom display conversion observer defined before the typing one
My observer converts the date fields into varchar/display formatted. Then when it hits the typing observer it leaves the updated_at alone and types the created_at back into an int and truncates everything after the first two number (ie: 12/20/2012 => 12)
I would expect any date field that I have defined as data_type=>'int' to behave the same and be truncated, but somehow the updated_at sneaks through fine
Problem I have is I have it defined as int so data will be typed correctly when getting retrieved by iOS/object-c for instance.
But want to display it in the date formatting of the user's choice. Will be experimenting with the _display property idea, also might add some more definition(s) onto each property and have formatting happen when its being used in a particular manner.., example might be $model->to_array('display')