I was following the guide here: http://www.yiiframework.com/wiki/22/how-to-display-static-pages-in-yii/
I had a scenario where I had a URL very similar to this:
http://www.example.com/index.php?r=site/page&view=help.contact
Can I easily rewrite it to this?
http://www.example.com/help/contact
I have working rules for pages, but it still requires me to use the . for a subfolder, not a /
'<view:(program|program.parents|program.teachers|sponsor)>'=>'site/page',
Asgaroth
(Asgaroth Belem)
May 19, 2011, 8:05pm
2
george3380:
I was following the guide here: http://www.yiiframework.com/wiki/22/how-to-display-static-pages-in-yii/
I had a scenario where I had a URL very similar to this:
http://www.example.com/index.php?r=site/page&view=help.contact
Can I easily rewrite it to this?
http://www.example.com/help/contact
I have working rules for pages, but it still requires me to use the . for a subfolder, not a /
'<view:(program|program.parents|program.teachers|sponsor)>'=>'site/page',
You cant use / there, i think there is no workaround.
Thanks, glad I didn’t waste my time
Asgaroth
(Asgaroth Belem)
May 19, 2011, 8:17pm
4
It was my opinion, but everything is always posible, i mean you can extend CUrlManager and change the format for static pages subdirectories from ‘.’ to say ‘//’ and make other modifications to get your desired behavior.
What I mean is that you can do this, out of the box IMO.
Y11
(Y!!)
May 19, 2011, 10:16pm
5
You can do:
'program' => array('site/page', 'defaultParams' => array('view' => 'program')),
'program/parents' => array('site/page', 'defaultParams' => array('view' => 'program.parents')),
...
You can do:
'program' => array('site/page', 'defaultParams' => array('view' => 'program')),
'program/parents' => array('site/page', 'defaultParams' => array('view' => 'program.parents')),
...
When viewing <domain>/program/parents I receive a 404 error: Unable to resolve the request "program/parents".
'gii'=>'gii',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'program' => array('site/page', 'defaultParams' => array('view' => 'program')),
'program/parents' => array('site/page', 'defaultParams' => array('view' => 'program.parents')),
Y11
(Y!!)
May 20, 2011, 3:42pm
7
Problems is <controller:\w+>/<action:\w+> matches the last rule. You should put such general rules on the bottom.
'gii'=>'gii',
'program' => array('site/page', 'defaultParams' => array('view' => 'program')),
'program/parents' => array('site/page', 'defaultParams' => array('view' => 'program.parents'))
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
Problems is <controller:\w+>/<action:\w+> matches the last rule. You should put such general rules on the bottom.
'gii'=>'gii',
'program' => array('site/page', 'defaultParams' => array('view' => 'program')),
'program/parents' => array('site/page', 'defaultParams' => array('view' => 'program.parents'))
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
Wow, sure enough. Thanks for your help, I wasn’t sure this was possible!
Final config:
'gii'=>'gii',
'program/parents' => array('site/page', 'defaultParams' => array('view' => 'program.parents')),
'program/teachers' => array('site/page', 'defaultParams' => array('view' => 'program.teachers')),
'program/hospitals' => array('site/page', 'defaultParams' => array('view' => 'program.hospitals')),
'<view:(program|get|sponsor|gallery|news)>'=>'site/page',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',