Child classes:
- ArraySerializer
- Array serializer.
- XmlSerializer
- XML serializer.
- CsvSerializer
- CSV serializer.
Class Details
Base class for Model serializers.
All serializers support the following options:
- only: a string or array of attributes to be included.
- except: a string or array of attributes to be excluded.
- methods: a string or array of methods to invoke. The method's name will be used as a key for the final attributes array along with the method's returned value
- include: a string or array of associated models to include in the final serialized product.
- only_method: a method that's called and only the resulting array is serialized
- skip_instruct: set to true to skip the <?xml ...?> declaration.
Example usage:
# include the attributes id and name # run $model->encoded_description() and include its return value # include the comments association # include posts association with its own options (nested) $model->to_json(array( 'only' => array('id','name', 'encoded_description'), 'methods' => array('encoded_description'), 'include' => array('comments', 'posts' => array('only' => 'id')) )); # except the password field from being included $model->to_xml(array('except' => 'password')));