次のコードでは、レコードを日付で検索する必要があります。私はをクリックし何でも、コード内の他の分岐が処理されますRadioListがレンダリングされていないようです
<?=$form->field($model, 'choice_date')->radioList(array(0=>'Before',1=>'After'))->label('Please, choose Datesearching!'); ?>
モデル:
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
class RadioForm extends Model { // A new Class programmed by Thomas Kipp
public $choice_date;
public function rules() {
return [
['choice_date', 'boolean'],
];
}
}
?>
探索クラス:
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Departments;
class DepartmentsSearch extends Departments {
public function rules() {
return [
[['department_id'], 'integer'],
[['department_name', 'department_created_date', 'department_status', 'companies_company_id', 'branches_branch_id'], 'safe'],
];
}
public function scenarios() {
return Model::scenarios();
}
public function search($params) {
$query = Departments::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) return $dataProvider;
$model = new RadioForm();
$model->load($params);
if ($model->choice_date == true)
$query->andFilterWhere(['<', 'department_created_date', $this->department_created_date]);
else
$query->andFilterWhere(['>', 'department_created_date', $this->department_created_date]);
$query->joinWith('companiesCompany');
$query->joinWith('branchesBranch');
$query->andFilterWhere(['like', 'department_name', $this->department_name])
->andFilterWhere(['like', 'companies.company_name', $this->companies_company_id])
->andFilterWhere(['like', 'branches.branch_name', $this->branches_branch_id])
->andFilterWhere(['like', 'department_status', $this->department_status]);
return $dataProvider;
}
}
P.S:私はちょうどこのような場合のために、真/偽日付フィルタリング変化する性質に影響を与えることができる午前:この問題を解決する方法を、
public $choice_date=true;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
任意のアイデア?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'if($ model-> choice_date == 0)'が常にfalseであると言っていますか? –
正確です。この部分は決してTRUEにはなりません。したがって、日付は常に大きいものとしてフィルタリングされます。私はちょうどユーザーではなく、モデルでのフィルタリングに影響を与えることができます。だから、私は、プロパティはレンダリングされません – tklustig
これはあなたのコードから、その部分が選択されたオプションに関係なく常に 'true'を返さなければならないので、これは奇妙です。 –