summaryrefslogtreecommitdiff
path: root/framework/Data
diff options
context:
space:
mode:
authorDavid Marko <dmarko484@gmail.com>2014-01-07 14:28:27 +0100
committerDavid Marko <dmarko484@gmail.com>2014-01-07 14:28:27 +0100
commit3f7dab44ea0b45dcdc5d590d94659010ef1eddda (patch)
treeda301d175b5379f72ed91c86b1ec203f93e1c044 /framework/Data
parentac4eaa30cc19cddec0aae5621d136a5a5fe7777c (diff)
Adding toArray() and toJSON() to TActiveRecord
Diffstat (limited to 'framework/Data')
-rw-r--r--framework/Data/ActiveRecord/TActiveRecord.php23
1 files changed, 23 insertions, 0 deletions
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());
+ }
}
/**