summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorctrlaltca <ctrlaltca@gmail.com>2014-01-10 01:35:52 -0800
committerctrlaltca <ctrlaltca@gmail.com>2014-01-10 01:35:52 -0800
commitd306b0341b678c2f57559cc89e1ae9d512b01bf4 (patch)
treeda301d175b5379f72ed91c86b1ec203f93e1c044
parentac4eaa30cc19cddec0aae5621d136a5a5fe7777c (diff)
parent3f7dab44ea0b45dcdc5d590d94659010ef1eddda (diff)
Merge pull request #494 from dmarko484/master
Adding toArray() and toJSON() to TActiveRecord
-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());
+ }
}
/**