Yii2 在记录中搜索日期失败

Yii2 在记录中搜索日期失败,yii2,Yii2,以下代码应搜索记录中的日期。但无论我单击什么,条件中的主分支都将被执行,因此我将得到输出: choice_date is false 将搜索=部门\创建\日期的记录 有什么想法,怎么解决这个问题 这是我的放射科医生 <?php use yii\helpers\Html; use kartik\grid\GridView; use yii\widgets\ActiveForm; $this->title = Yii::t('app', 'Departments'); $this-

以下代码应搜索记录中的日期。但无论我单击什么,条件中的主分支都将被执行,因此我将得到输出:

choice_date is false
将搜索=部门\创建\日期的记录 有什么想法,怎么解决这个问题

这是我的放射科医生

<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\ActiveForm;

$this->title = Yii::t('app', 'Departments');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="departments-index">
    <h1><?= Html::encode($this->title) ?></h1>
    <?php
    $form = ActiveForm::begin();
    $model = new backend\models\DepartmentsSearch();
    ?><?= $form->field($model, 'choice_date')->radioList(array(0 => 'Before', 1 => 'After'))->label('Please, choose Datesearching!'); ?>
    <p><?= Html::a(Yii::t('app', 'Create Departments'), ['create'], ['class' => 'btn btn-success']) ?></p>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [
                'attribute' => 'branches_branch_id',
                'label' => Yii::t('app', 'Branch'),
                'value' => function($model) {
                    if ($model->branches_branch_id) {
                        return $model->branchesBranch->branch_name;
                    } else {
                        return NULL;
                    }
                },
                'filterType' => GridView::FILTER_SELECT2,
                'filter' => backend\models\Branches::getBranchList(),
                'filterWidgetOptions' => [
                    'pluginOptions' => ['allowClear' => true],
                ],
                'filterInputOptions' => ['placeholder' => 'Branch', 'id' => 'grid-Branch-search-rechtsart']
            ],
            'branchesBranch.branch_name',
            'department_name',
            [
                'attribute' => 'companies_company_id',
                'label' => Yii::t('app', 'Company'),
                'value' => function($model) {
                    if ($model->companies_company_id) {
                        return $model->companiesCompany->company_name;
                    } else {
                        return NULL;
                    }
                },
                'filterType' => GridView::FILTER_SELECT2,
                'filter' => backend\models\Companies::getCompanyList(),
                'filterWidgetOptions' => [
                    'pluginOptions' => ['allowClear' => true],
                ],
                'filterInputOptions' => ['placeholder' => 'Company', 'id' => 'grid-Company-search-rechtsart']
            ],
            'department_created_date',
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]);
    ?>
</div>
在这里,进一步的方法是不相关的。为什么日期记录的属性不会呈现在视图中

}
视图中的$model是RadioForm,因此表单将此字段作为RadioForm[choice_date]发送

但您希望选择部门搜索模型的日期,此字段留空

移除无线电模型,这完全不需要。在表单视图中使用部门搜索模型

更新:

由于OP最终告诉我这是一个GridView,我可以更新我的答案以适合他

GridView中有一个filterSelector属性可供使用-您可以在其中设置用于筛选的其他jQuery选择器

以下是更新的代码和注释:

<?php $form = ActiveForm::begin();
echo $form->field($searchModel /* 1 */, 'choice_date')->radioList([
    0 => 'Before', 1 => 'After'
], ['itemOptions' => ['class' => 'choiceRadio' /* 2 */]])->label('Please, choose Datesearching!');
ActiveForm::end(); /* 3 */ ?>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'filterSelector' => '.choiceRadio', /* 4 */
    // ...
这就是我刚才说的$searchModel。这里不需要任何其他型号。 你可以在这里设置任何你想要的CSS类,它是为filterSelector设置的。 不要忘记像在原始代码中那样关闭表单。 这是收音机输入的选择器。注意符号-。对于CSS类,对于CSS id。
你确定吗?通常在控制器中初始化模型,以便将请求参数传递给搜索方法并在视图中输出结果。您正在将参数从请求传递到搜索方法吗?请改进-也许-我的控制器请参见您已经将$searchModel传递到视图。只需在表单中使用$searchModel而不是$model。请给我一个例子。不幸的是,我不明白你们的共同点:=P.S.:我也必须使用这个模型,因为它代表了我的放射科医生,我给了你们所有的奖项,可以在这个平台上颁发!!
}
<?php $form = ActiveForm::begin();
echo $form->field($searchModel /* 1 */, 'choice_date')->radioList([
    0 => 'Before', 1 => 'After'
], ['itemOptions' => ['class' => 'choiceRadio' /* 2 */]])->label('Please, choose Datesearching!');
ActiveForm::end(); /* 3 */ ?>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'filterSelector' => '.choiceRadio', /* 4 */
    // ...