Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx

上传人:PIYPING 文档编号:11652349 上传时间:2021-08-28 格式:DOCX 页数:4 大小:12.12KB
返回 下载 相关 举报
Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx_第1页
第1页 / 共4页
Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx_第2页
第2页 / 共4页
Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx_第3页
第3页 / 共4页
Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx》由会员分享,可在线阅读,更多相关《Yii净化器CHtmlPurifier用法示例(过滤不良代码)_.docx(4页珍藏版)》请在三一文库上搜索。

1、Yii净化器CHtmlPurifier用法示例(过滤不良代码)_ 这篇文章主要介绍了Yii净化器CHtmlPurifier用法,可实现过滤不良代码的功能,涉及在掌握器、模型、过滤器及视图中的相关用法技巧,需要的伴侣可以参考下 1. 在掌握器中用法: public function actionCreate() $model=new News; $purifier = new CHtmlPurifier(); $purifier-options = array( URI.AllowedSchemes=array( http = true, https = true, ), HTML.Allowe

2、d=div, ); if(isset($_POSTNews) $model-attributes=$_POSTNews; $model-attributescontent = $purifier-purify($model-attributescontent); if($model-save() $this-redirect(array(view,id=$model-id); 2. 在模型中的用法: protected function beforeSave() $purifier = new CHtmlPurifier(); $purifier-options = array( URI.Al

3、lowedSchemes=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( accessContr

4、ol, / 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($_POSTnews) $_POSTnewscontent = $purify($_POSTnewscontent); $filterChain-run(); 4. 在视图中的用法: ?php $this-beginWidget(CHtmlPurifier); ? .display user-entered content here. ?php $this-endWidget(); ? 盼望本文所述对大家基于Yii框架的PHP程序设计有所关心。 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1