1

description我想在 CDetailView 中将输出属性作为 HTML 代码。

<?php $this->widget('zii.widgets.CDetailView', array(
    'data'=>$model,
    'attributes'=>array(
        'id',
        'title',
        'description' => array(
            'name' => 'description',
            'value' => html_entity_decode(CHtml::decode($model->description)),
        ),
        'price',
        'date',
    ),
));?>
4

1 回答 1

10

您将需要使用以下:html格式:

'attributes'=>array(
        'id',
        'title',
        'description:html',
        'price',
        'date',
    ),

对于其他格式,请参阅CFormatter

您甚至可以扩展 CFormatter,并创建自己的格式。

<?php
class CustomFormatter extends CFormatter {

    public function formatLink($value) {
        return '<a href="'.$value.'">'.$value.'</a>';
    }

    public function formatBold($value) {
        return '<b>'.$value.'</b>';
    }

    public function formatArray($value) {
        return (is_array($value)) ?
            implode(', ', $value) : $value;
    }
}

如果您扩展 CFormatter,请更新项目的main.php以指向新文件:

// application components
'components' => array(

    'format' => array(
        'class' => 'application.extensions.CustomFormatter',
    ),

    ...
),

示例用法:

    'title:bold',
    'website:link',
    'tags:array',
于 2013-09-02T02:52:20.190 回答