Why is the data not saved?

I want to save data coming from the form, here is the method in the controller
public function actionCreate()
{
 $model = new Post();
 if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
 $model->user_id = \Yii::$app->user->getId();
 $model->created_at = \Yii::$app->formatter->asDate(new \DateTime(),'php:Y-m-d');
 $model->image = UploadedFile::getInstance($model, 'image');
 if($model->upload()) {
 $model->image = ('web/images/' . $model->image->baseName . '.' . $model->image->extension);
 } else {
 $model->image = null;
}
$model->save();
 return $this->redirect(['site/blog']);
 } else {
 return $this->render('blog/create', ['model' => $model]);
}
 }

and the model itself:
class Post extends ActiveRecord
{
 public $title;
 public $text;
 public $image;
 public $comments;

 public function rules()
{
 return [
 [['title', 'text'], 'required'],
 [['image'], 'file', 'extensions' => 'png, jpg'],
];
}
 public function upload()
{

 if ($this->image->saveAs(\Yii::getAlias('@app') .'\web\images\\' . $this->image->baseName . '.' . $this->image->extension))
 return true;
 else {
 return false;
}
}
 public function getComments()
{
 return $this->hasMany(Comment::className(), ['post_id' => 'id']);
}
 public function getUser()
{
 return $this->hasOne(User::className(),['id' => 'user_id']);
}
}


But now when sending forms are only saved created_at,user_id and all. Ie those fields which I asked explicitly. What's wrong?
June 14th 19 at 20:12
2 answers
June 14th 19 at 20:14
Good morning.
In model add method
public function behaviors()
{
 return [
TimestampBehavior::className()
];
}

In the controller to remove
$model->created_at = \Yii::$app->formatter->asDate(new \DateTime(),'php:Y-m-d');

Replace
$model->user_id = \Yii::$app->user->getId();
on
$model->user_id = Yii::$app->user->identity->id;
At the beginning of the controller to add
use Yii;
a slash in front of Yii anywhere to remove.
What fields are You passing?
The picture may not pass the validation, so not saved. Highlight all of the code that is responsible for loading images in a separate model.
June 14th 19 at 20:16
Why model the explicit Declaration of attributes? Remove all public attributes.

Find more questions by tags PHPYii