summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Marko <dmarko484@gmail.com>2014-01-07 14:28:27 +0100
committerDavid <ottodavid@gmx.net>2014-08-21 17:21:23 +0200
commit30cd2aea091bdf455cb8d3464264ba7292330a96 (patch)
treed67d4d155afa4692fb7c6ebd18790778c4d7df90
parentdcaa0390c1d1335f47f0dd4b8784dc550e3d9f93 (diff)
Adding toArray() and toJSON() to TActiveRecord(cherry picked from commit 3f7dab44ea0b45dcdc5d590d94659010ef1eddda)
-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());
+ }
}
/**