简体   繁体   English

有关网址中参数的疑问

[英]Doubts about parameter in the URL

I have the following form to the address below: 我将以下表格发送到以下地址:

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();

Who processes and generates the following URL: 谁处理并生成以下URL:

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

But I need only the category_id value (selected in dropDownList). 但是我只需要category_id值(在dropDownList中选择)。 That is, the URL should be: 也就是说,URL应该是:

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

How to stay that way or get just the category_id 如何保持这种方式或仅获取category_id

In view add registerJs : 在视图中添加registerJs

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

And not use ActiveForm::begin... and all your code. 并且不要使用ActiveForm::begin...和所有代码。 Instead of use this: 而不是使用此:

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 --']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM