title: Change limit of queries in Yii2
body: <p>I want to create searchModel with Yii2, my query have default limit is 7, and I have an input dropdownlist on the page to switch limit of query between 7 and 30. </p>
  
  <p>How I can do this?</p>
  
  <pre><code>&lt;?php $form = ActiveForm::begin(); ?&gt;
      &lt;?= $form-&gt;field($modelSearch, 'limit')-&gt;dropDownlist([
          7 =&gt; '7 days',
         30 =&gt; '30 days',
      ]); ?&gt;
  &lt;?php ActiveForm::end(); ?&gt;
  </code></pre>
  
  <p>and this is Model</p>
  
  <pre><code>class SearchModel extend \yii\base\Models
  {
      public $limit;
      public function search($params) {
          $query = Objects::find()-&gt;where(['attribute1'=&gt;'a', 'attribute2'=&gt;b]);
          $dataProvider = new ActiveDataProvider([
              'query' =&gt; $query,
              'sort' =&gt; ['attributes' =&gt; ['attribute1', 'attribute2',]]
          ]);
  
          $this-&gt;load($params);
          return $dataProvider;
      }
  }
  </code></pre>
  
  <p>and this is controller</p>
  
  <pre><code>public function actionIndex()
  {
       $searchModel = new ModelSearch();
       $dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;post());
       return $this-&gt;render('index', [
           'searchModel' =&gt; $searchModel,
           'dataProvider' =&gt; $dataProvider,
       ]);
  }
  </code></pre>
  
  <p>I've tried to add</p>
  
  <pre><code>if(empty($params['limit'])) {
           $query-&gt;limit(7);
       }else {
           $query-&gt;limit($params['limit']);
       }
  </code></pre>
  
  <p>into the models - it worked but I think it's not a smart way to resolve it.</p>