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
my .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /Yii/app/
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
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>',
)
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"
}
Can someone help me?
EDIT:
It musst work for a variable nummber of get parameters.
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>',
With such rule, you can obtain the URL as
/de/user/admin/id/2/test2/hello/anotherparam/45/yap/thisothertoo
and bind $_GET params as
'id' => 2
'test2' => 'hello'
'anotherparam' => 45
'yap' => 'thisothertoo'
Last thing to keep in mind: check always rule precedence.
You should simply try to add this url rule :
'<language:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>/test/<test:\w+>'=>'<controller>/<action>',
And with Yii you don't really need to use $_GET
, you should use action parameter binding feature : http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#action-parameter-binding
Here is the solution , you can uri component use like this ; Yii::app()->uri->segment(2);
for details follow url
http://www.hasandemir.com/how-to-get-contoller-action-segments-like-codeigniter/