1

我正在使用 get 方法在 Yii 中与 Cactiveform 作斗争。这是我的代码:

<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'inlineForm',
    'type'=>'inline',
  'method'=>'get',
  'action'=> array('searchview'),
    'htmlOptions'=>array('class'=>'well'),
)); 
echo $form->dropDownListRow($model, 'year',$arrYears); 
echo $form->dropDownListRow($model, 'month',$mons); 
echo $form->dropDownListRow($model, 'day',$days); 
$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary','label'=>'Vyhledat')); 
  $this->endWidget(); ?>

当我单击提交按钮时,我得到这个 URL:

http://stavbadomusvepomoci.cz/stavba_naklady/index.php?r=expenses%2Fsearchview&Expenses%5Byear%5D=2013&Expenses%5Bmonth%5D=0&Expenses%5Bday%5D=0&yt0=

问题是字段的名称是 Expenses[year] 插入的只是:year。当我删除它时,这个 url 工作得很好。

http://stavbadomusvepomoci.cz/stavba_naklady/index.php?r=expenses%2Fsearchview&year=2013&month=0&day=0&yt0=

我的搜索返回 400 错误,因为它无法识别 url。我使用调节器 CHtml::beginForm 进行此工作,但我希望这可以与 CActive 表单一起使用。

所以我的问题是:我怎样才能摆脱 url 中的 Expenses[] 以便 cactiveform 起作用。

谢谢您的回答!

4

1 回答 1

1

我建议在服务器端使用 $_GET["Expenses"] 而不是整个 $_GET 数组,因为它可能包含与搜索无关的变量,例如 CSRF 令牌。

我看到实现您想要的唯一方法是 dropDownListRow 的 htmlOptions 参数。您可以给它一个特定的名称,这会导致 yii 不设置模型属性依赖名称。

$form->dropDownListRow($model, 'year', $arrYears, array("name" => "year")); 
于 2013-08-08T15:52:05.777 回答