You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yii框架CButtonColumn中Addendum按钮跳转异常求助

问题原因

你的CButtonColumn中addendum按钮的url配置错误,Yii 1.x要求url属性是可执行的PHP表达式,而非直接包裹双引号的字符串。当前写法'"http://www.google.com"'无法被正确解析,导致生成的链接href为#,无法跳转。

另外,生成的<a>标签title值异常(显示为label的HTML代码),是因为Yii默认会将label作为按钮的title,你需要确保options里的title生效,同时允许label使用HTML不被转义。

解决方案

修改按钮配置如下:

array(
    'class' => 'CButtonColumn',
    'template' => '<div class="actions-box">{edit}{views}{print}{print_contract}{print1}{addendum}</div>',
    'buttons' => array(
        'addendum' => array(
            'label' => '<i class="fa fa-print" style="color:grey"></i>',
            'encodeLabel' => false, // 允许label使用HTML代码
            'options' => array(
                'title' => 'Addendum',
                'target' => '_blank',
            ),
            'url' => 'http://www.google.com', // 直接写入URL,去掉外层多余双引号
        ),
    ),
),

如果需要基于当前模型生成动态URL(比如携带数据ID参数),可以使用PHP表达式拼接:

'url' => '"http://www.google.com?id=" . $data->id',
验证效果

修改后生成的<a>标签应如下所示,点击即可正常在新标签页跳转至目标地址:

<a title="Addendum" target="_blank" href="http://www.google.com"><i class="fa fa-print" style="color:grey"></i></a>

内容的提问来源于stack exchange,提问作者Sona Rijesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 22:52:11