Hello,
I’m new with yii
I come from codeIgniter and in this framework the parameter binding automatically binds url parameters with action parameters by omitting the parameter name in the url.
For exemple, if i have an action like :
public function actionLogin($id){...}
I would like to use this url :
host://domain.com/site/login/100
instead of :
host://domain.com/site/login/id/100
Of course, the $id value would be 100.
I read the guide : http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-named-parameters but I didn’t find a route pattern that matches my needs.
An other question :
When I use parameter binding with useStrictParsing, the application throws a 404 even when I use an url such as :
host://domain.com/site/login/id/100
Do you know why ?
Thanks,
Maxime.
andy_s
(Arekandrei)
November 30, 2011, 9:04am
2
The url rule should look like:
'site/login/<id:\d+>'=>'site/login',
About the useStrictParsing option read here: http://www.yiiframework.com/doc/api/1.1/CUrlManager#useStrictParsing-detail
Thanks,
I use a default Yii installation. In this installation i uncommented the url manager to have urlFormat as Path.
And it looks like :
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
So I already have a default route:
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
for (controller/action/id):
'site/login/<id:\d+>'=>'site/login',
Plus it is not working for me right now.
For the useStrictParsing param, this page http://www.yiiframew …tParsing-detail does not tell me what it is for:
whether to enable strict URL parsing. This property is only effective when urlFormat is ‘path’. If it is set true, then an incoming URL must match one of the URL rules. Otherwise, it will be treated as an invalid request and trigger a 404 HTTP exception. Defaults to false.
Any url that doesn’t match a route pattern won’t throw a 404 whether useStrictParsing is set to true or false ?? So in which case should i use the useStrictParsing => true ?
Thanks,
Maxime.
Can someone help me plz ?
Ok, I get it !
The parameter name of the action did not match the url pattern’s parameter name xD.
Is there any way I can declare a parameter in the url pattern (like <id>) that match any kind of parameter name in the action ?
For exemple the pattern would match this :
public function actionLogin($var) {...}
public function actionLogin($id) {...}
public function actionLogin($test) {...}
without declaring 3 different patterns such as :
'site/login/<var:\d+>'=>'site/login',
'site/login/<id:\d+>'=>'site/login',
'site/login/<test:\d+>'=>'site/login'
Thanks,
Maxime.