1

我只想将 GET-param 从用户添加到 URL。我使用第三方模块操作,所以我不想更改签名

public function actionReset($id, $code)

我在控制器中有这样的模型

$model = new DynamicModel([
    'code'
]);
$model->addRule(['code'], 'required');
$model->addRule(['code'], 'string');

诸如此类ActiveForm

<?php $form = ActiveForm::begin([
    'method' => 'get',
    'action' => [
        \yii\helpers\Url::current()
    ]
]) ?>

<?php echo $form->field($model, 'code')->textInput()->label(false); ?>

<?php echo Html::submitButton(Yii::t('user', 'Continue')); ?>

<?php ActiveForm::end(); ?>

通过这样的实现,它通过一个数组包装器传递:

在此处输入图像描述

如果没有自定义 js,是否可以避免这种包装器?

4

2 回答 2

2

可能是您可以在 activeForm 配置中指定它

       <?php $form = ActiveForm::begin([
          'method' => 'get',
          'action' => [
              \yii\helpers\Url::current(), 'your_att' => $your_value
          ]
      ]) ?>

或数组格式

      <?php $form = ActiveForm::begin([
          'method' => 'get',
          'action' => [
              \yii\helpers\Url::current(), ['your_att' => $your_value],
          ]
      ]) ?>
于 2016-10-28T18:34:17.173 回答
0

我在这里找到了答案

现在我的视图代码看起来像

            <?=Html::beginForm(Url::current(), 'get', ['csrf' => false]);?>
            <?=Html::input('text', 'code', 'test')?>

            <?=Html::a('Submit', '', [
                'data' => [
                    'method' => 'get',
                ]
            ])?>
            <?=Html::endForm();?>
于 2016-10-28T19:03:22.833 回答