url - 当 Yii urlManager 的 urlFormat 设置为 'path' 时,如何解析 GET 样式参数?

标签 url yii

我的应用程序是为了使用 Yii clean url 而编写的。 urlManager 将 urlFormat 设置为路径,因此应用程序需要“/home/login/12”形式的参数。

我的问题是,我使用的第三方 API 类需要“/api/login?user_id=12&foo=234234&bar=xyzzy”形式的回调。这些参数在 $_GET 中不可用,因为 Yii 不会将它们解释为单独的参数。

如何告诉 urlManager 对这个 Controller 使用 get urlFormat?

更新:

我的 urlManager 配置选项:

'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
        // Other paths
        '/' => 'home/index',
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
),

我的测试查询字符串:

http://localhost/testcontroller/testaction?id=x&blah=y
http://localhost/testcontroller/testaction/?id=x&blah=y

我使用的是 Yii 版本 1.1.10.r3566。

最佳答案

正如 dInGd0nG 所指出的,问题存在于我们的重写规则中。

他们是这样的:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?req=$1

当他们应该是这样的时候:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule . index.php

关于url - 当 Yii urlManager 的 urlFormat 设置为 'path' 时,如何解析 GET 样式参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10581738/

相关文章:

c++ - 打开转义文件时出现意外行为 :///URL in IE

mysql - 如何在 Yii 中添加日志记录?

yii - 使用我的作品时使用 IronWorkers

url - 捕获 Rust 中的错误(Rust URL)

javascript - 确定使用了哪个链接(在同一页面上)?

ruby - 在 Ruby 中解析 URL 字符串

Cakephp 和 Yii : similarities/differences/speed?

forms - Yii 事件形式有哪些替代方案?

php - MySQL Union All 在 Yii 的默认范围内

c# - ASP.NET - 基于动态内容生成网页