有没有办法为每个url都加上一个参数?

我想得到这样的url(http://www.abc.com/index.php/username/articles/list)。

用了这样的url rules(’/<username:\w+>/<_c:>/<_a:>’ => ‘<_c>/<_a>’,)。

可以得到上面的url,但是我先要为每个createUrl都加上当前用户名,如下:


<?php echo CHtml::link('gallery', $this->createUrl('gallery/list',array('username'=>Yii::app()->user->name))); ?>

现在有没有什么办法直接给所有url都加上username而不用手工为每个都加上这个params?

你可以自己写一个JUrlManager,继承CUrlManager,

改写里面的 createUrl() 方法,

判断是否为登录用户,假如是,就加上你的 username参数,即可~

在你的baseController里,重写createUrl方法即可

按照jeryy的方法已经完成,谢谢两位