Art*_*lev 1 html php format widget yii
我希望输出属性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',
),
));?>
Run Code Online (Sandbox Code Playgroud)
Sam*_*iew 10
您将需要使用以下:html格式:
'attributes'=>array(
'id',
'title',
'description:html',
'price',
'date',
),
Run Code Online (Sandbox Code Playgroud)
有关其他格式,请参阅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;
}
}
Run Code Online (Sandbox Code Playgroud)
如果扩展CFormatter,请更新项目的main.php以指向新文件:
// application components
'components' => array(
'format' => array(
'class' => 'application.extensions.CustomFormatter',
),
...
),
Run Code Online (Sandbox Code Playgroud)
用法示例:
'title:bold',
'website:link',
'tags:array',
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5136 次 |
| 最近记录: |