From a5188f1fbcc54af5db33c0772553180135033df2 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 7 Dec 2013 12:30:09 -0500 Subject: [PATCH] Fixes #1457: support string representation of AR. --- framework/yii/db/BaseActiveRecord.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/framework/yii/db/BaseActiveRecord.php b/framework/yii/db/BaseActiveRecord.php index 00360c4..767ab00 100644 --- a/framework/yii/db/BaseActiveRecord.php +++ b/framework/yii/db/BaseActiveRecord.php @@ -93,6 +93,17 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface /** + * Returns the string representation of this AR instance. + * The default implementation will return the primary key (or JSON representation of the primary key if it is composite). + * @return string the string representation of this AR instance. + */ + public function __toString() + { + $pk = $this->getPrimaryKey(); + return is_array($pk) ? json_encode($pk) : $pk; + } + + /** * Creates an [[ActiveQuery]] instance for query purpose. * * @include @yii/db/ActiveRecord-find.md