I have a problem while routing my requests in Yii. Following is the urlManager rules:
'rules'=>array(
array('api/index', 'pattern'=>'api/<model:\w+>/<id:\d+>/*', 'verb'=>'GET'),
array('api/shortlist', 'pattern'=>'api/<action>/<model:\w+>/*', 'verb'=>'GET'),
array('api/compare', 'pattern'=>'api/<action>/<model:\w+>/*', 'verb'=>'GET'),
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
My requests get routed to api/shortlist even if I hit the api/compare link.
What am I doind wrong here?
As you can see, the patterns for your
shortlistandcomparerules are the same.Therefore, the rule that is placed first will match for both, and the second one will never run.
Your
api/comparerule will never match/hit because the rule above it is the same and will match first.You should have done something like this to prevent conflict: