Hey,
This is a question of "good practice" on implementing OO design.
I have CActiveRecord model classes, that I want to make available through json for writing API GET methods (no SOAP needed, just returning data).
The question is, how to do it the right OO way. Example:
I have a class models/Shop.php (CActiveRecord) that has fields: id, name, content, created_at, updated_at.
Now, for the API, I want to return in JSON only the name, content and created_at fields.
What I am doing now, is:
$apiObject = $activeRecordObject->getAttributes();
unset($apiObject[‘id’],$apiObject[‘updated_at’]);
return json_encode($apiObject);
but I think this is not how it should be done. I thought about doing a "model" class like ShopAPI that defines only the public attributes I want, and then doing:
$apiObject = (ShopAPI) $activeRecordObject;
but maybe you have other good practice solutions for doing such an API?