如何使用html '的链接功能,而不链接到'索引'


How to use CHtml's link function without linking to 'index'?

我正在使用CHtml::link()函数,并且我对索引操作有问题。

查看代码:

echo CHtml::link('Watch it', array('video/index', 'id' => $id));

配置中的urlManager部分:

'urlManager' => array(
        'urlFormat' => 'path',
        'rules' => array(
            '<id>/<action>' => 'video/<action>',
            '<id>' => 'video/index'
        )
    )

我想让它创建一个链接到:

http://localhost/123
相反,它创建一个链接到:
http://localhost/123/index

如何删除'/index'部分?

创建一个函数来处理这个(用什么都不替换'/index')将是最好的解决方案?

您可以在html链接函数中使用Yii::app()->createUrl

echo CHtml::link('Watch it', Yii::app()->createUrl('video/index', 'id' => $id));

'urlManager' => array(
        'urlFormat' => 'path',
        'rules' => array( 
            '<id>' => 'video/index'
            '<id>/<action>' => 'video/<action>',
        )
    )