在管理方面,我为所有textareas使用了WYSIWYG编辑器。
例如,当我们用粗体格式化时,以下字符串存储在数据库中:
<b>hello bold</b>
但是,当我尝试以粗体显示该文本时,我会看到类似的内容:
"<b>hello bold</b>"
目标(所以我想)将删除那些双引号,以便让我们看到正确的格式化文本。
这是小部件调用:
<?php $this->widget('bootstrap.widgets.BsListView',array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
));
以下是他所说的观点:
<b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
<?php echo $data->description; ?><!-- Removed the encode from this line-->
<br />
如果我删除了CHtml::encode
,这可行,但是,如果我有500个textareas,我应该转到每个视图并删除此CHtml::encode
:s
有任何线索吗?
答案 0 :(得分:4)
您可以使用PHP“html_entity_decode”功能解决此问题
看看这里:http://www.yiiframework.com/forum/index.php/topic/22237-clistview-raw-html/
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$b = html_entity_decode($a);
echo $b; // I'll "walk" the <b>dog</b> now
?>
参考:http://www.php.net/html_entity_decode
<强>更新强>
当你打印html标签包含数据时,你应该删除chtml :: encode。这就是问题所在。
encode()的用法是将特殊字符编码为HTML实体http://yiiframework.com/doc/api/1.1/CHtml#encode-detail