title: Validating content before save in yii2
body: <p>I am using <code>yii2</code> for a weigh bridge project</p>
  
  <p>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. </p>
  
  <p>How can I implement the validation property</p>
  
  <p>Controller code:</p>
  
  <pre><code> public function actionCreate()
  {
      $model = new TruckWeight1();
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) ) {
  
          $model-&gt;time_recorded =date('H:i:s');;
          $model-&gt;recorded_by =
          $model-&gt;recorded_date = date('Y-m-d');
  
          $model-&gt;save();
  
          return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;id]);
  
      } else {
          return $this-&gt;render('create', [
              'model' =&gt; $model,
          ]);
      }
  }
  </code></pre>