对URL中的参数有疑问


Doubts about parameter in the URL

我有以下表格到下面的地址:

http://localhost/myapp/web/index.php?r=cashbook%2Faccomplishment

$form = ActiveForm::begin([
        'id' => 'accomplishment-form',
        'options' => ['class' => 'form-horizontal'],
        'action' => Url::to(['/cashbook/accomplishment']),
                'method' => 'get',
]);
$form->field($model, 'category_id')->dropDownList(ArrayHelper::map(
                Category::find()->where(['user_id' => Yii::$app->user->identity->id])
                                ->orderBy("desc_category ASC")
                                ->all(), 'id_category', 'desc_category'),
                ['onchange'=>'this.form.submit()','prompt'=>'-- Select --']); 
ActiveForm::end();

谁处理并生成以下URL:

http://localhost/myapp/web/index.php?r=cashbook%2Faccomplishment&Cashbook%5Bcategory_id%5D=18

但我只需要category_id值(在dropDownList中选择)。也就是说,URL应该是:

http://localhost/myapp/web/index.php?r=cashbook%2Faccomplishment&category_id=19

如何保持这种状态或只获得category_id

在视图中添加registerJs:

$this->registerJs('var submit = function (val){
if (val > 0) {
    window.location.href = "' . Url::to(['/cashbook/accomplishment']) . '/?category_id=" + val;
}
}', View::POS_HEAD);

不要使用ActiveForm::begin...和所有代码。不用这个:

echo Html::activeDropDownList($model, 'id_category', ArrayHelper::map(
            Category::find()->where(['user_id' => Yii::$app->user->identity->id])
                            ->orderBy("desc_category ASC")
                            ->all(), 'id_category', 'desc_category'), ['onchange'=>'submit(this.value);','prompt'=>'-- Select --']);