iThink
iThink

Reputation: 1259

url manager yii

These I've added as my following rules:

'search/do'=>'search/do',
'search/do/<town:.*?>'=>'search/do',
'search/do/<town:.*?>/<cat:.*?>'=>'search/do',
'search/do/<town:.*?>/<cat:.*?>/<scat:.*?>'=>'search/do',

the url search/do & search/do/chicago working fine. But search/do/chicago/restaurants gives an error for $_GET['cat'] (undefined index cat)

Upvotes: 2

Views: 898

Answers (1)

bool.dev
bool.dev

Reputation: 17478

Just make sure the rules are in decreasing order of specificity . More specific rules should come first, followed by the lesser ones:

'search/do/<town:.*?>/<cat:.*?>/<scat:.*?>'=>'search/do',
'search/do/<town:.*?>/<cat:.*?>'=>'search/do',
'search/do/<town:.*?>'=>'search/do',
'search/do'=>'search/do',

The rules in your question matched chicago/restaurants to $_GET['town'] because of the second rule : 'search/do/<town:.*?>'=>'search/do', and it didn't navigate to the third rule. So you should have the specific ones first.

Upvotes: 5

Related Questions