rakete
rakete

Reputation: 3041

Yii url route with parameters

At the moment i have a glossar controller with an actionAnzeige()-method.

For this action i need GET-paramter named item.

Now i could use this url: www.xy.de/glossar/anzeigen?item=programming

But i want to use this: www.xy.de/glossar/programming

I've added this route to the rules:

'glossar/<item:\d+>'=>'glossar/anzeigen',

and now i can generate the url i want to use:

<?php echo Yii::app()->createUrl('glossar/anzeigen', array('item' => $glossarItem->Url)); ?>

But if i visit the created url, i get a 404 error.

Upvotes: 1

Views: 4468

Answers (2)

Brett Gregson
Brett Gregson

Reputation: 5913

You can use this, which accepts characters or numbers:

'glossar/<item:.+>'=>'glossar/anzeigen',

Upvotes: 4

dInGd0nG
dInGd0nG

Reputation: 4114

You have to use w+ instead of d+ since item takes letters instead of digits

'glossar/<item:\w+>'=>'glossar/anzeigen',

Upvotes: 3

Related Questions