启用PrettyUrl后,URL参数出错

时间:2016-02-02 00:29:36

标签: yii2

我有以下DropDownList,我选择了更新图表的类别。一切正常,直到我启用“enablePrettyUrl”。

现在当我选择DropDownList中的任何值时出现错误

  

“未找到(#404)”。

可能出现什么问题?

查看:

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

                echo Html::activeDropDownList($model, 'category_id', 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'=>Yii::t('app','Select'),'class'=>'form-control']);
                ?>

控制器:

public function actionAccomplishment()
    {
        $model = new Dashboard();

        $url = Yii::$app->getRequest()->getQueryParam('category_id');
        $category_id = isset($url) ? $url : 0;
        $thisyear  = date('Y');
        $thismonth = date('m');
        $user    = Yii::$app->user->identity->id;

我的网址管理员:

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'showScriptName' => false,
    'enablePrettyUrl' => true,
    'rules' => array(
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    ),
],

2 个答案:

答案 0 :(得分:1)

尝试添加/并删除&amp;这样

window.location.href = "' . Url::to(['/dashboard/accomplishment/']) . 'category_id=" + val;

答案 1 :(得分:1)

这种方式工作: window.location.href = "' . Url::to(['/dashboard/accomplishment']) . '?category_id=" + val;