Commit 4ec95e6d by Qiang Xue

Fixes issue #600.

parent 1e93fcf2
......@@ -8,6 +8,7 @@
namespace yii\behaviors;
use yii\base\Behavior;
use yii\base\Event;
use yii\db\Expression;
use yii\db\ActiveRecord;
......@@ -64,30 +65,27 @@ class AutoTimestamp extends Behavior
*/
public function events()
{
$events = array();
$behavior = $this;
foreach ($this->attributes as $event => $attributes) {
if (!is_array($attributes)) {
$attributes = array($attributes);
}
$events[$event] = function () use ($behavior, $attributes) {
$behavior->updateTimestamp($attributes);
};
$events = $this->attributes;
foreach ($events as $i => $event) {
$events[$i] = 'updateTimestamp';
}
return $events;
}
/**
* 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)
{
$attributes = isset($this->attributes[$event->name]) ? (array)$this->attributes[$event->name] : array();
if (!empty($attributes)) {
$timestamp = $this->evaluateTimestamp();
foreach ($attributes as $attribute) {
$this->owner->$attribute = $timestamp;
}
}
}
/**
* Gets the current timestamp.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment