1

我正在使用该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' 替换为空)将是解决此问题的最佳解决方案吗?

4

1 回答 1

3

您可以在 chtml 链接功能中使用 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>',

        )
    )
于 2014-08-03T12:02:09.987 回答