title: Yii2: $model->validate() is not working
body: <p>I wanna create my own login method, but firstly I may try to work with validation and then redirect to the page; however, the validate() method is not working.
  Here is my code.
  LoginController:</p>
  
  <pre><code>&lt;?php
  namespace backend\controllers;
  
  use yii\web\Controller;
  use common\models\LoginForm;
  use Yii;
  
  
  class LoginController extends Controller{
  
      public $layout = 'login' ;
  
      public function actionIndex(){
  
          $model = new LoginForm();
  
              if($model-&gt;load(Yii::$app-&gt;request-&gt;post() &amp;&amp; $model-&gt;validate())){
                  return $this-&gt;redirect(['site/index']);
              }else{
              var_dump(Yii::$app-&gt;request-&gt;isPost);
              echo "&lt;br&gt;";
              var_dump($model-&gt;load(Yii::$app-&gt;request-&gt;post()));    
              echo "To be continued...";
              }
  
          return $this-&gt;render('index',['model' =&gt; $model]);
      }
  
  }
  </code></pre>
  
  <p>Here it is the LoginForm.php:</p>
  
  <pre><code>&lt;?php
  namespace common\models;
  
  use Yii;
  use yii\base\Model;
  use common\models\User;
  
  class LoginForm extends Model{
  
      public $username;
      public $password;
      public $rememberMe = true;
      public $verification;
  
      public function rules(){
          return [
              [['username','password'],'required','message'=&gt;'{attribute}Write Something...'],
              ['username','validateUser'],
              //['password', 'validatePassword'],
              ];
      }
  /*Continue later after redirect works    
      public function validateUser($attribute,$params){
          $user = User::findOne(['username'=&gt;$this-&gt;$attribute]);
          if(!$user || (md5($this-&gt;password) != $user['password'])){
              $this-&gt;addError($this-&gt;attribute,'Errors Here...');
          }
  
      }
  */
  </code></pre>
  
  <p>And here is my login/index.php</p>
  
  <pre><code>&lt;?php
  use yii\helpers\Html;
  use Yii;
  
  //http://www.yiiframework.com/doc-2.0/guide-output-client-scripts.html
  $this-&gt;registerCssFile('@web/css/bslogin.css');
  
  ?&gt;
  
  &lt;div class="container"&gt;
  &lt;?=Html::beginForm('','post',['class'=&gt;'form-signin'])?&gt;
  
          &lt;h2 class="form-signin-heading"&gt;Please sign in&lt;/h2&gt;
  
          &lt;?=Html::activeInput('text',$model,'username',['id'=&gt;'username','class'=&gt;'form-control','placeholder'=&gt;'Username','autofocus'=&gt;true])?&gt;
          &lt;?=Html::error($model,'username')?&gt;
  
          &lt;?=Html::activeInput('password', $model,'password',['id'=&gt;'inputPassword','class'=&gt;'form-control','placeholder'=&gt;'Password'])?&gt;
          &lt;?=Html::error($model,'password')?&gt;
          &lt;div class="checkbox"&gt;
            &lt;label&gt;
              &lt;input type="checkbox" value="remember-me"&gt; Remember me
            &lt;/label&gt;
          &lt;/div&gt;
          &lt;?=Html::submitButton('Login',['class'=&gt;'btn btn-lg btn-primary btn-block'])?&gt;
  &lt;?=Html::endForm()?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>So, the issues are:</strong></p>
  
  <ul>
  <li><ol>
  <li>While accessing and validating the user input, no matter what I type,
  the Error would show up, either Blank or Filled with values.</li>
  </ol></li>
  <li><ol start="2">
  <li>If I remove the <strong>$model->validate()</strong> from <strong>Controller</strong>, page will redirect to the index, but it is without validation.</li>
  </ol></li>
  <li><ol start="3">
  <li>If I comment the username validation on the rules, just check for required, error would show the same. Input or blank will display
  error message that "Write Something".</li>
  </ol></li>
  </ul>
  
  <p>Not sure where I did wrong, any helps would appreciated.</p>