Search code examples
urlyiiurl-mapping

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.


Solution

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

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