using group widget with json instead of xml

A place for users and developers of the Xataface to discuss and receive support.

using group widget with json instead of xml

Postby whiteatom » Sun Oct 14, 2012 3:58 pm

Hi there.. new to xataface and I am so far... impressed. I would like to adjust one thing though. I use a fair bit of JSON encoded fields to store meta data and it would be very helpful if I could get xataface to read and write JSON data behind the group widget instead of xml. Is there a pluggable system for parsers? is there anyway I could customize this without tearing the entire app apart?
whiteatom
 
Posts: 2
Joined: Sun Oct 14, 2012 3:50 pm

Re: using group widget with json instead of xml

Postby shannah » Tue Oct 16, 2012 7:07 am

Yes you can implement your own serializer for that field by implementing the fieldname__serialize() method in the delegate class. I'm going to need to look through my notes to find an example of this method for you. ... will post soon
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: using group widget with json instead of xml

Postby whiteatom » Sun Oct 21, 2012 3:57 pm

That would be wicked :) when ever you get a chance.. the docs are pretty poor for that kind of stuff.
whiteatom
 
Posts: 2
Joined: Sun Oct 14, 2012 3:50 pm

Re: using group widget with json instead of xml

Postby shannah » Fri Oct 26, 2012 8:33 am

You can implement fieldname__parse() and fieldname__serialize() methods to override the serialization and loading of fields in your database. E.g.
Code: Select all
function myfield__parse($data){
    if ( is_string($data) ){
        return json_decode($data, false);
    }
    return $data;
}

function myfield__serialize($data){
    return json_encode($data);
}


Haven't tested this particular code, but should work.

You may want to check out
http://weblite.ca/svn/dataface/core/tru ... Record.php (the setValue() method is it asks the table to parse input).
http://weblite.ca/svn/dataface/core/tru ... /Table.php (the parse() method...)
http://weblite.ca/svn/dataface/core/tru ... alizer.php (actually does the serialization).

Implementing xxx__parse() and xxx__serialize() overrides the default mechanisms.
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 15 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved