国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

Yii凈化器CHtmlPurifier用法示例(過濾不良代碼)

2024-05-04 23:48:11
字體:
來源:轉載
供稿:網友

本文實例講述了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));  }}

2. 在模型中的使用:

protected function beforeSave(){  $purifier = new CHtmlPurifier();  $purifier->options = array(    'URI.AllowedSchemes'=>array(              'http' => true,              'https' => true,    ),       'HTML.Allowed'=>'div',  );  if(parent::beforeSave()){    if($this->isNewRecord){      $this->create_data = date('y-m-d H:m:s');      $this->content = $purifier->purify($this->content);    }    return true;  }else{    return false;  }}

3. 在過濾器中的使用:

public function filters(){  return array(    'accessControl', // perform access control for CRUD operations    'postOnly + delete', // we only allow deletion via POST request    'purifier + create', //載入插入頁面時進行些過濾操作  );}public function filterPurifier($filterChain){  $purifier = new CHtmlPurifier();  $purifier->options = array(    'URI.AllowedSchemes'=>array(              'http' => true,              'https' => true,    ),       'HTML.Allowed'=>'div',  );  if(isset($_POST['news']){    $_POST['news']['content'] = $purify($_POST['news']['content']);  }    $filterChain->run();}

4. 在視圖中的使用:

<?php $this->beginWidget('CHtmlPurifier'); ?>...display user-entered content here...<?php $this->endWidget(); ?>

希望本文所述對大家基于Yii框架的PHP程序設計有所幫助。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 崇明县| 芒康县| 龙川县| 西安市| 卢氏县| 伊川县| 常山县| 东平县| 定陶县| 安化县| 固镇县| 务川| 曲沃县| 久治县| 安远县| 建平县| 玛沁县| 浦东新区| 年辖:市辖区| 南木林县| 老河口市| 乌兰浩特市| 仪陇县| 客服| 富裕县| 泌阳县| 康马县| 长垣县| 东阿县| 宜宾市| 成武县| 临泉县| 辽宁省| 奉化市| 峡江县| 平邑县| 陆川县| 皮山县| 宁武县| 阿拉善左旗| 舒兰市|