Discuz!X json输出解析后模板

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
示例如下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值