Sarke
January 12, 2011, 5:24am
1
Hi,
I currently have the basic URL Manager rulers set so that this…
domain.com/index.php?r=topic/view&id=123&page=2&sort=time.desc
turns into this…
domain.com/topic/123/page/2/sort/time.desc
However. what I would like is for it to only parse the ID parameter into the path, and leave the rest in the query string, like this…
domain.com/topic/123&page=2&sort=time.desc
Is that possible, and if so, how?
gusnips
(Gustavo)
January 12, 2011, 6:23am
2
i didnt quite undertand what you want but
a rule like this:
'<_module:\w*>/<_controller:\w*>/<_action:\w+>/<id:\d+>'=>'<_module>/<_controller>/<_action>',
'<_module:\w*>/<_controller:\w+>/<id:\d+>'=>'<_module>/<_controller>',
'<_module:\w*>/<id:\d+>'=>'<_module>',
will put the last parameter if its numeric in the variable $_GET[‘id’]
ncs
(Mradar)
January 12, 2011, 6:42am
3
use the rule
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'topic/<id:\d+>'=>'topic/view',
),
)
Sarke
January 12, 2011, 8:20am
4
Gustavo and ncs, thanks for your replies. However, both of those do what I have now: they put ALL the parameters into the path.
FYI, this is what I have now.
'<controller:\w+>'=>'<controller>/index',
'<controller:\w+>/<id:\d+>'=>'<controller>',
'<controller:\w+>/<id:\d+>/<action:\w+>'=>'<controller>/<action>',
To highlight what I want, I’ve put what I want changed and put in the path in green (incl. the ID), and the rest I have put in red (what I do not want changed but left in the query string).
From this
domain.com/index.php?r=[color="#00AA00"]topic/[/color]view&[color="#00AA00"]id=123[/color][color="#AA0000"]&page=2&sort=time.desc[/color]
To this
domain.com/[color="#00AA00"]topic/123[/color][color="#AA0000"]&page=2&sort=time.desc[/color]
Hopefully this explains what I am looking for. Is this possible??
ncs
(Mradar)
January 12, 2011, 2:24pm
5
it must work
‘topic/<id:\d+>’=>‘topic/view’ (id go to path, other params go to $_GET)
see http://www.yiiframework.com/doc/guide/1.1/en/topics.url (before first note)
iivano71
(Igor Zg1987)
January 12, 2011, 8:29pm
6
try
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'topic/<action:\w+>/<id:\d+>/<page:\d+>/<sort:\w+>'=>'topic/<action>',
),
)
or controller with query strings
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'topic/<id:\d+>/<page:\d+>/<sort:\w+>'=>'topic/view',
),
)
Sarke
January 12, 2011, 11:51pm
7
Igor Ivanovic, that’s exactly what I do not want. I’m trying to avoid having the ‘page’ and ‘sort’ parameters end up in the path.
ncs, the link created still looks like "domain.com/topic/123/page/2/sort/time.desc ".
Looking at the CUrlManager.createUrlDefault() source, I found that the “appendParams” options controls this behavior! Setting it to false seems to do what I want!
EDIT: This is how my urlManager looks now.
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'appendParams' => false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>',
'<controller:\w+>/<id:\d+>/<action:\w+>'=>'<controller>/<action>',
),
),
Thanks all!