php - 如何在 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,';
}
解决方案
默认情况下,所有操作参数都是标量。如果需要接受数组,则应在方法签名中明确指定此类型:
public function actionSelectedreport($reportoptions, array $reportselection, $fromdate, $todate)
推荐阅读
- scala - 带有doIf条件的加特林foreach循环
- python - 根据熊猫中的多个维度计算基于先前日期分组的行百分比变化
- javascript - 提交表单前调用javascript函数
- yubikey - 我的 Yubikey 在打开包装后是否可以安全使用,或者我应该设置它吗?
- database - Heroku 我在哪里可以保存文件?
- angular - Angular 9 / Angular Material - formArrayName 中的 formArrayName
- python - 位置索引
- python - 使用python从包含存储在另一个列表中的短语的列表中查找句子
- javascript - 使用 axios 做出本机反应时出现错误 404 - 请求失败,状态码为 404
- java - 如何在运行 JSP 页面之前运行 Servlet?