Yii2:如何在没有模型的情况下将变量从视图传递到控制器?

I am using the ActiveForm widget to send a model from the view to the controller. It works great but now I also need to send a checkbox that is not part of any model. This is my checkbox:

<?= Html::checkbox('swim', false, ['id' => 'idSwim']) ?>

If my checkbox is part of a model, I could send it in this way:

<?= $form->field($myCheckboxModel, 'swim')->checkbox(['id' => 'idSwim') ?>

But it doesn't belong to any model, so I don't know how to send it. I even send different models in the same forms.

Retrieve the posted value in your controller like this:

$swim = Yii::$app->request->post('swim')

If the field is related to one of your models, you could also consider defining it as a property: http://www.yiiframework.com/doc-2.0/guide-concept-properties.html