From 3dc598bc7c2604e24b9e0be1189d9d78b43737ea Mon Sep 17 00:00:00 2001 From: wei <> Date: Wed, 17 Jan 2007 08:01:40 +0000 Subject: Add active record generator. --- framework/Data/ActiveRecord/TActiveRecord.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'framework/Data/ActiveRecord/TActiveRecord.php') diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index d3e25dcf..9272e1b9 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -97,12 +97,26 @@ abstract class TActiveRecord extends TComponent */ public function __construct($data=array(), $connection=null) { - foreach($data as $name=>$value) - $this->$name = $value; + $this->copyFrom($data); if($connection!==null) $this->_connection=$connection; } + /** + * Copies data from an array or another object. + * @throws TActiveRecordException if data is not array or not object. + * @return TActiveRecord current instance. + */ + public function copyFrom($data) + { + $data = is_object($data) ? get_object_vars($data) : $data; + if(!is_array($data)) + throw new TActiveRecordException('ar_must_copy_from_array_or_object', get_class($this)); + foreach($data as $name=>$value) + $this->$name = $value; + return $this; + } + /** * Gets the current Db connection, the connection object is obtained from * the TActiveRecordManager if connection is currently null. @@ -212,7 +226,7 @@ abstract class TActiveRecord extends TComponent /** - * Delete multiple records using a criteria. + * Delete multiple records using a criteria. * @param string|TActiveRecordCriteria SQL condition or criteria object. * @param mixed parameter values. * @return int number of records deleted. -- cgit v1.2.3