Browse Source

Fixes issue #600.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
4ec95e6dc2
  1. 26
      framework/yii/behaviors/AutoTimestamp.php

26
framework/yii/behaviors/AutoTimestamp.php

@ -8,6 +8,7 @@
namespace yii\behaviors; namespace yii\behaviors;
use yii\base\Behavior; use yii\base\Behavior;
use yii\base\Event;
use yii\db\Expression; use yii\db\Expression;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
@ -64,28 +65,25 @@ class AutoTimestamp extends Behavior
*/ */
public function events() public function events()
{ {
$events = array(); $events = $this->attributes;
$behavior = $this; foreach ($events as $i => $event) {
foreach ($this->attributes as $event => $attributes) { $events[$i] = 'updateTimestamp';
if (!is_array($attributes)) {
$attributes = array($attributes);
}
$events[$event] = function () use ($behavior, $attributes) {
$behavior->updateTimestamp($attributes);
};
} }
return $events; return $events;
} }
/** /**
* Updates the attributes with the current timestamp. * Updates the attributes with the current timestamp.
* @param array $attributes list of attributes to be updated. * @param Event $event
*/ */
public function updateTimestamp($attributes) public function updateTimestamp($event)
{ {
$timestamp = $this->evaluateTimestamp(); $attributes = isset($this->attributes[$event->name]) ? (array)$this->attributes[$event->name] : array();
foreach ($attributes as $attribute) { if (!empty($attributes)) {
$this->owner->$attribute = $timestamp; $timestamp = $this->evaluateTimestamp();
foreach ($attributes as $attribute) {
$this->owner->$attribute = $timestamp;
}
} }
} }

Loading…
Cancel
Save