Discuz!X json输出解析后模板
来源:互联网 发布:守望先锋生涯数据出错 编辑:程序博客网 时间:2024/06/06 08:25
Discuz的模板机制可以很方便的用HTML写出前端模板,然后将模板直接输出到浏览器。
一般情况是,解析的模板是整个页面的。直接将需要更新的页面部分输出即可,不过有些时候可能要一个json传送多组数据。这样直接输出就不行了。再手写一个输出到字符串的template
显然也比较麻烦。
实际利用输出缓冲就可以达到相应的目的。下面是一段关于php的输出缓冲(output buffering)的描述,因此利用输出缓冲就能够达到需要的效果。
Without output buffering, PHP sends data to your web server as soon as it is ready - this might be line by line or code block by code block. Not only is this slow because of the need to send lots of little bits of data, but it also means you are restricted in the order you can send data. Output buffering cures these ills by enabling you to store up your output and send to send it when you are ready to - or to not send it at all, if you so decide.
整体来说,输出缓冲将本该输出到浏览器的内容拦截在了当前脚本的内存缓冲区中。所以使用输出缓冲后,需要从缓冲区中提取(ob_get_contents
)。ob_get_clean
相当于执行ob_get_contents
后再执行ob_clean
。
示例如下:
ob_start(); //开始使用output buffering ob_clean(); //清空之前的output buffering include template('replay_tool:replayblock'); //调用discuz!X的模板解析函数 $html = ob_get_clean(); //从output buffering取出模板内容 echo json_encode(array( 'total' => $totalcnt, 'maxpage' => $maxpage, 'html' => $html, )); //输出json
这样在主页面模板里用js取出html放进相应的容器内部就可以了。
实际上正如那段话所叙述,需要打乱输出顺序进行重组的,利用输出缓冲是很好解决的。
- Discuz!X json输出解析后模板
- Discuz!X模板代码解析--Header(头文件)
- Discuz!模板解析语法
- discuz模板机制解析
- PHP模板解析引擎--discuz
- discuz 解析模板 分析 自己用
- Discuz模板文件space_blog.htm解析
- cocos2d-x Json解析
- Unity5.x 解析Json
- 【discuz】discuz模板语法
- 【discuz】discuz模板语法
- quick-cocos2d-x解析json
- cocos2d-x json解析 jsonBox
- cocos2d-x json解析 jsonBox
- cocos2d-x json解析 jsonBox
- cocos2d-x lua json解析
- cocos2d-x RapidJson解析json
- jersey2.x 解析json字符串
- scikit-learn机器学习库
- Invalid nested tag br found, expected closing tag li 错误解决
- thinkphp5.0学习(二):tp5.0架构和运转流程
- 欢迎使用CSDN-markdown编辑器
- 12.leetCode690. Employee Importance
- Discuz!X json输出解析后模板
- android精确绘制文字位置的方法
- C#中属性和字段的区别
- Linux创建用户并加入sudoers文件
- 实现HttpClient重试
- 原生js实现的鼠标滑上去之后按照屏幕高度放大缩略图
- Window 透明窗体的实现总结
- OpenCV-将JPG图像的第二个通道和第三个通道的值设置为最大值
- 多线程创建的四种方式