I am creating a test project with Yii2 and trying to use the timestamp behavior but having a hard time implementing it. I have created the model and CRUD for the table market and have attempted to add a behavior to models/Market.php as follows:
<?php
namespace app\models;
use yii\behaviors\TimestampBehavior;
class Market extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at',
],
],
];
}
However, when loading the page I get the error
Class 'yii\behaviors\TimestampBehavior' not found
I’ve searched the whole source code including vendor/yiisoft but there is no class of TimestempBehavior anywhere. Do I need to include/install it some other way first?
When I’m using TimestampBehavior on the user model, I don’t need to specify:
use yii\behaviors\TimestampBehavior;
So maybe that is the problem. I was having a different problem with it. The default behavior is to set an integer and I wanted a time stamp. In that case, I had to make 2 changes:
I initially installed Yii2 using Composer and I can see that it is alpha. Generally with Composer I would type ‘composer update’ to update but this doesn’t change anything. How would I go about upgrading to a newer version?