我在索引中有兩個dropDownlist,當我選擇提交按鈕時,它將在控制器中得到動作,並且它執行一些操作並再次使用gridview渲染索引,但是所選dropDownList變爲空白,我怎麼能在dropDownllist中設置默認?如何在dropDownlist中顯示默認值
任何建議應appreciatable ...... 這是我的看法
<div class="col-sm-12" align="center">
<?= $form->field($model, 'fk_int_payroll_month')->dropDownList(
ArrayHelper::map(TblPayrollMonth::find()->all(), 'pk_int_payroll_month_id','vchr_month'),
['prompt'=> 'Select...'])
?>
</div>
<div class="col-sm-12" align="center">
<?= $form->field($model, 'fk_int_payroll_year')->dropDownList(
ArrayHelper::map(TblPayrollYear::find()->all(), 'pk_int_payroll_year_id','year'),
['options' => [isset($_POST['fk_int_payroll_year'])?'fk_int_payroll_year':'' => ['Selected'=>true]]],
['prompt'=> 'Seect...'])
?>
</div>
這是我的控制器
public function actionDisplay()
{
$model = new TblPayroll();
if(Yii::$app->request->post()!=null)
{
$data = Yii::$app->request->post();
// var_dump($data);
// die;
$month = $data['TblPayroll']['fk_int_payroll_month'];
$year = $data['TblPayroll']['fk_int_payroll_year'];
/* Be careful with this! */
$dataProviderSearch = new ActiveDataProvider
([
'query' => TblPayroll::find()->where(['fk_int_payroll_month'=>$month, 'fk_int_payroll_year'=> $year]),
'pagination' => ['pageSize' => 5],
]);
if($dataProviderSearch)
{
return $this->render('index', [
'dataProviderSearch' => $dataProviderSearch,
'model' => $model,
]);
}
}
else{
return $this->render('index', ['model' => $model]);
}
當我選擇下拉會戈特actionDisplay,並找到數據提供者,然後它再次渲染到索引,以便該如何顯示默認的選擇值dropDownlist?
那些下拉列表關聯到'$ model',因此他們有VALU e他們各自的模型領域有 – gmc
我只獲得單一的價值所有,,如何定義我的選項 – Midlaj
assingn的默認值是關係到模型..請更新您的問題,並添加您的相關控制器/行動代碼 – scaisEdge