我的应用程序是为了使用 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/