在yii2中保存之前验证内容

I am using yii2 for a weigh bridge project

Upon create, the user is redirected to view but my controller doesn't validate the information in such a way that even if data is not entered in the form fields a user is always redirected to view.

How can I implement the validation property

Controller code:

 public function actionCreate()
{
    $model = new TruckWeight1();

    if ($model->load(Yii::$app->request->post()) ) {

        $model->time_recorded =date('H:i:s');;
        $model->recorded_by =
        $model->recorded_date = date('Y-m-d');

        $model->save();

        return $this->redirect(['view', 'id' => $model->id]);

    } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}

try this

public function actionCreate()
{
    $model = new TruckWeight1();

    if ($model->load(Yii::$app->request->post()) && $model->validate()) {

        $model->time_recorded =date('H:i:s');;
        $model->recorded_by =
        $model->recorded_date = date('Y-m-d');

        $model->save();

        return $this->redirect(['view', 'id' => $model->id]);

    } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}

for more on validation validation