Yii says it can automatically set the timestamps 'created_at': http://www.yiiframework.com/doc-2.0/guide-concept-behaviors.html#using-timestampbehavior
However, every time I created a record, the time is blank:
$ yii kw/test
1437683634
mysql> select * from ad_group_keyword_network where ad_group_keyword_id = 1;
+---------------------+-
| created_at |
+---------------------+-
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
+---------------------+-
public function actionTest() {
$agkn = new AdGroupKeywordNetwork();
$agkn->save();
echo $agkn->created_at;
I tried with Schema::TYPE_TIMESTAMP
and I changed the field and also tried with Schema::TYPE_DATETIME
. They both return an integer timestamp in the field after save, but the time is all 0s in the database.
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => [],