如何从编码 URL 中获取 Yii 2 中的请求变量?

How to get request variables in Yii 2 from encoded URL?

我的问题很基础,但我想不通 - 也许我在这里遗漏了一些基本概念。

我正在这样的菜单中创建 link URL:

['label' => Icon::show("newspaper") . Yii::t('app', 'News'), 'url' => ['site/index', ['section' => 'news']], 'options' => ['class' => 'mobile-menu']],

它生成如下URL(出现在地址栏中):

http://localhost/websitename/web/site/index?1%5Bsection%5D=main

我无法使用 Yii::$app->request->getQueryParam('section') 从 URL 中提取 GET 变量 - 这是我需要帮助的地方。我要么用错了,要么我需要先做一些事情,要么我以错误的方式生成 URLs...谁知道呢? :)

注意:如果我像这样手动输入地址栏,它会起作用:

http://localhost/websitename/web/site/index?section=main

所以我认为 URL 编码把事情搞砸了(部分)...

非常感谢! 安德拉斯

您已将参数嵌套在另一个数组中。 它们只需要是 url 数组中的 key => value

['label' => Icon::show("newspaper") . Yii::t('app', 'News'), 'url' => ['site/index', 'section' => 'news'], 'options' => ['class' => 'mobile-menu']],