本文实例讲述了Yii净化器CHtmlPurifier用法。分享给大家供大家参考,具体如下:
1. 在控制器中使用:
public function actionCreate()
{
$model=new News;
$purifier = new CHtmlPurifier();
$purifier->options = array(
'URI.AllowedSchemes'=>array(
'http' => true,
'https' => true,
),
'HTML.Allowed'=>'div',
);
if(isset($_POST['News']))
{
$model->attributes=$_POST['News'];
$model->attributes['content'] = $purifier->purify($model->attributes['content']);
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
}
页:
[1]