-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp Behavior #235
Comments
Don't think it's a good idea since the amount of code required to implement it nearly equals the amount of code to attach behavior. |
The difference between behavior and implementing it in core is obvious. Many beginner coders are expecting that to be core functionality of the modern framework and I can say from my programming experience, that when I was still learning and was very new to yii I didn't know anything about behaviors and didn't bother to look at them, but I have used core functionality to the fullest from the first days. Another argument is that many modern ORMs and frameworks implement this in core. |
Old well-known timestamp behaviour ported to 2.0: https://gist.github.com/resurtm/5567517 (might be helpful for someone). |
And another request about this: http://www.yiiframework.com/forum/index.php/topic/43225-activerecord-timestamps/ Just opened another suggestion for a behavior that might be helpful for some. #249 Revision count behavior. |
Yeah, showcasing is important. We may reconsider it. |
Vote to add that behavior to core. |
Class name suggestion: |
Vote to add to the core as well... |
Done. |
Suggest newest behavior, to extends count of timestamp attributes class AutoTimestamp extends Behavior
{
public $attributes = array(
'create_time' => ActiveRecord::EVENT_BEFORE_INSERT,
'update_time' => ActiveRecord::EVENT_BEFORE_UPDATE,
);
public $timestamp;
public function events()
{
$events = array();
foreach ($this->attributes as $attribute => $event) {
$events[$event] = function($event) use ($attribute) {
$event->sender->updateTimestamp($attribute);
};
}
return $events;
}
public function updateTimestamp($attribute)
{
$this->owner->$attribute = $this->evaluateTimestamp($attribute);
}
protected function evaluateTimestamp($attribute)
{
if ($this->timestamp instanceof Expression) {
return $this->timestamp;
} elseif ($this->timestamp !== null) {
return call_user_func($this->timestamp);
} else {
return time();
}
}
} |
@slavcodev good idea. @yiisoft/core-developers I think having more than two timestamp fields is possible. |
Thank you for your suggestion. Done via e69afe3 |
@qiangxue, @samdark, what do you think about the idea of developing good old well-known timestamp behavior in Yii 2.0 too? :-)
The text was updated successfully, but these errors were encountered: