Browse Source

Fixes #1457: support string representation of AR.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
a5188f1fbc
  1. 11
      framework/yii/db/BaseActiveRecord.php

11
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

Loading…
Cancel
Save