title: Yii2: how to remove required attribute in a view?
body: <p>I have a text field that was defined as required in its model. But a view needs not be required. I try this way to remove the <strong>required</strong> attribute but it doesn't work:</p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'city')-&gt;textInput(['required' =&gt; false]) ?&gt;
  </code></pre>
  
  <p>I need to change it in a <strong>view</strong> or in its <strong>controller</strong>. But not in its <strong>model</strong> (because others view needs the required attribute.).</p>
  
  <p>I know how to do it using <strong>jQuery</strong> but I prefer with <strong>PHP/Yii2</strong>. </p>
  
  <p><strong><em>Update (requiered by the nice help of @Muhammad Omer Aslam):</em></strong></p>
  
  <ul>
  <li><p>My model is called <strong>Persons</strong>.</p></li>
  <li><p>My view is called <strong>_form</strong>.</p></li>
  <li><p>My controller is called <strong>PersonsControllers</strong>. It has the update function:</p></li>
  </ul>
  
  <p>actionUpdate($id):</p>
  
  <pre><code>public function actionUpdate($id)
  {
      $model = $this-&gt;findModel($id); // How to add my new scenario here?
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
          return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;id_person]);
      }
  
      return $this-&gt;render('update', [
          'model' =&gt; $model,
      ]);
  
  }
  </code></pre>