Using Parameterizing Routes in CHtml.lnk

Hello guys,

In Url management tutorial having a special topic, that describe how to use UrmManage.

I’d tried it within CHtml::link, but it seem not work!

In my code, I were created a CGridview and in girdview, I have a column that content a CHtml::link like this (Id is following format: ‘xx xx’, so I use str_replace to format it to xxxx):


                'header' => 'ID',

                'type' => 'raw',

                'name' => 'id',

                'value' => 'CHtml::link($data->id, Yii::app()->createUrl("lichchay/viewbienso", array("id"=>str_replace(" ", "", $data->id),"month"=>date("m"),"year"=>date("Y"))), array("style" => "text-decoration: none"))',


In browser, it displays in status bar like this:


It is not user-friendly url :), why don’t it following my url format that was config before in config/main.php?

And in config/main.php:


            'showScriptName' => false,






                '<_c:(lichchay)>/<_a:(viewbienso)>/<id:\d>/<month:\w>/<year:\w>' => '<_c>/<_a>',



In UrlManager, I added the last one.


You need to change the order of your rules. The first matching rule "wins". Match in this case means: All parameters used in the rule are present in the given parameters (which is different from "All given parameters are present in the rule"!). So put your last rule on top. Rules should be ordered from most special to most generic.

Thanks, let me try it :lol:

Beside the order, you may have a problem with the regular expression, since you accept only one decimal (\d) or letter (\w):

'<_c:(lichchay)>/<_a:(viewbienso)>/<id:\d+>/<month:\d+>/<year:\d+>' => '<_c>/<_a>',