php - Yii2 Getting user input from a form -


i making search query user find property within price range. not know how yii2 gets user input. here code form:

  <?php $form = activeform::begin([     'action' => ['index'],     'method' => 'get', ]); ?>  <?= $form->field($model, 'address') ?>  <?= $form->field($model, 'minprice')->dropdownlist(['£100' => '£100','£200' => '£200','£300' => '£300']) ?>   <?= $form->field($model, 'maxprice')->dropdownlist(['£100' => '£100','£200' => '£200','£300' => '£300']) ?>  <div class="form-group">     <?= html::submitbutton('search', ['class' => 'btn btn-primary']) ?>     <?= html::resetbutton('reset', ['class' => 'btn btn-default']) ?> </div>  <?php activeform::end(); ?>     

and here model:

class propertiessearch extends properties {   public $minprice;  public $maxprice;  public function search($params) {     $query = properties::find();      $dataprovider = new activedataprovider([         'query' => $query,     ]);      $this->load($params);      if (!$this->validate()) {         return $dataprovider;     }      $query->andfilterwhere([         'id' => $this->id,         'noofbedrooms' => $this->noofbedrooms,         'type_id' => $this->type_id,     ]);      $query->andfilterwhere(['like', 'address', $this->address])         ->andfilterwhere(['like', 'city', $this->city])         ->andfilterwhere(['like', 'postcode', $this->postcode])         ->andfilterwhere(['>=', 'price', $this->minprice])         ->andfilterwhere(['<=', 'price', $this->maxprice])         ->andfilterwhere(['=', 'option', $this->option])         ->andfilterwhere(['like', 'description', $this->description]);    return $dataprovider; } } 

i added public $minprice , $maxprice receiving error:

getting unknown property: app\models\propertiessearch::minprice

however, query doesn't work, in url shows user input query isn't following through. have thought ($model, 'minprice') gives field name , $this-minprice gets value. works when make public $minprice = '$100' , $maxprice = '$300', must overwriting users input, if remove them previous error again, doing wrong?

try put propetries $minprice , $maxprice in model app\models\properties , add conddition validate.

class properties extends activerecord {   public $minprice;  public $maxprice;  ... 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -