I’m new to Yii and would like to define possible GET parameters in urlManager rules in the main.php config file and then access those parameters from within the Controller without worrying about sanitizing.
For example considering the following rule in main.php config:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'<action:myaction>/<year:\d{2}|\d{4}>' => 'site/<action>'
)
)
Using the url "site/myaction?year=abc"
Yii::app()->request->getParam('year','default');
returns "abc" even though I would really expect "default" to be returned.
Using the url "site/myaction/2010", 2010 is returned, which is ok.
However how can I tell which case is used?
The latter case gives me the expected value, whereas the first case leaves me accepting any value. So I would need to sanitize in the Controller anyway.
What am I doing wrong?