Php Yii2从表单获取用户输入

Php Yii2从表单获取用户输入,php,forms,input,yii2,Php,Forms,Input,Yii2,我正在为用户进行搜索查询,以查找价格范围内的房产。我不知道Yii2是如何获得用户输入的。以下是我的表单代码: <?php $form = ActiveForm::begin([ 'action' => ['index'], 'method' => 'get', ]); ?> <?= $form->field($model, 'address') ?> <?= $form->field($model, 'minprice

我正在为用户进行搜索查询,以查找价格范围内的房产。我不知道Yii2是如何获得用户输入的。以下是我的表单代码:

  <?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(); ?>    

这是我的模型:

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;
}
}
类属性搜索扩展属性
{
公费$minprice;
公费$maxprice;
公共函数搜索($params)
{
$query=Properties::find();
$dataProvider=新的ActiveDataProvider([
'query'=>$query,
]);
$this->load($params);
如果(!$this->validate()){
返回$dataProvider;
}
$query->andFilterWhere([
'id'=>this->id,
“NoofBedrooms”=>this->NoofBedrooms,
'type\u id'=>this->type\u id,
]);
$query->andFilterWhere(['like','address',$this->address])
->andFilterWhere(['like','city',$this->city])
->andFilterWhere(['like','Postcode',$this->Postcode])
->andFilterWhere(['>=','price',$this->minprice])

->andFilterWhere(['在model app\models\Properties中尝试放置属性$minprice和$maxprice 并添加条件验证

class Properties extends ActiveRecord
{

 public $minprice;
 public $maxprice;

...

您能显示模型中的规则吗?很可能load()无法将内容分配给没有规则的属性。