yii路径url中的多个GET变量 [英] Multiple GET-variables in yii path url

查看:79
本文介绍了yii路径url中的多个GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Yii urlManager有问题。我正在使用路径格式,并希望传递多个get变量。网址看起来像这样:

I have a problem with my Yii urlManager. I'm using the path format and want to pass multiple get variables. The url looks like that:

/Yii/app/de/user/admin/id/5/test/hello 

我的.htaccess:

my .htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /Yii/app/
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

我尝试使用urlManager,但不适用于以下规则:

I tried with the urlManager, but it doesn't work with following rules:

'rules' => array(
    '<language:\w+>/<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<language:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<language:\w+>/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
)

$ _ GET应该看起来像这样:

The $_GET should look like this:

array(3) { 
    ["/de/user/admin"]=> string(0) ""
    ["id"]=> string(1) "5" 
    ["test"]=> string(5) "hello" 
    ["language"]=> string(2) "de" 
}

有人可以帮助我吗?

编辑:

对于可变数量的get参数来说,它是无效的。

It musst work for a variable nummber of get parameters.

推荐答案

保留官方指南 URL管理-使用命名参数作为参考。

Keep the official guide URL Management - Using named parameters as reference.

您应编写一个自定义规则,例如:

You should write a custom rule such as:

'<language:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>/test/<test:\w+>'=>'<controller>/<action>'

特别是,如果要具有可变数量的参数,则应附加 / * ,如下所示:

In particular, if you want to have a variable number of arguments, you should append /* to the rule, something like this:

'<language:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',

使用此规则,您可以获得的URL为

With such rule, you can obtain the URL as

/de/user/admin/id/2/test2/hello/anotherparam/45/yap/thisothertoo

并绑定$ _ GET params as

and bind $_GET params as

'id' => 2
'test2' => 'hello'
'anotherparam' => 45
'yap' => 'thisothertoo'

最后要记住的是:始终检查 规则优先级。

Last thing to keep in mind: check always rule precedence.

这篇关于yii路径url中的多个GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆