From 30cd2aea091bdf455cb8d3464264ba7292330a96 Mon Sep 17 00:00:00 2001 From: David Marko Date: Tue, 7 Jan 2014 14:28:27 +0100 Subject: Adding toArray() and toJSON() to TActiveRecord(cherry picked from commit 3f7dab44ea0b45dcdc5d590d94659010ef1eddda) --- framework/Data/ActiveRecord/TActiveRecord.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'framework/Data/ActiveRecord/TActiveRecord.php') diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index b94f1336..735579cd 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -1023,6 +1023,29 @@ abstract class TActiveRecord extends TComponent { return isset(self::$_relations[get_class($this)][strtolower($property)]); } + + /** + * Return record data as array + * @return array of column name and column values + * @since 3.2.4 + */ + public function toArray(){ + $result=array(); + foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){ + $result[$columnName]=$this->getColumnValue($columnName); + } + + return $result; + } + + /** + * Return record data as JSON + * @return JSON + * @since 3.2.4 + */ + public function toJSON(){ + return json_encode($this->toArray()); + } } /** -- cgit v1.2.3