首页 > 解决方案 > 如何在 yii2 中返回数组值?

问题描述

我的视图代码是:

<?= $form->field($model, 'ReportSelection[]')->dropdownlist(['1' => 'Channel1', '2' => 'channel2','3'=>'channel3','4'=>'channel4'],['multiple'=>'multiple']); ?>

我的控制器代码是:

return $this->redirect(['selectedreport','fromdate'=>$model->FromDate,'todate' => $model->ToDate,'reportselection' =>$model->ReportSelection,'reportoptions' => $model->ReportOption]);

我的动作功能是:

public function actionSelectedreport($reportoptions,$reportselection,$fromdate,$todate)

我需要$reportselection作为参数在这里使用:

foreach($reportselection as $i)   
{
    $selectlist = $selectlist . 'Channel'.$i.'Value,';
}

标签: phparraysyii2

解决方案


默认情况下,所有操作参数都是标量。如果需要接受数组,则应在方法签名中明确指定此类型:

public function actionSelectedreport($reportoptions, array $reportselection, $fromdate, $todate)

推荐阅读