码迷,mamicode.com
首页 > Web开发 > 详细

PHP Smarty 返回页面内容方法

时间:2015-07-02 10:22:33      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

使用$smarty->display()时是没有办法将页面以字符串的形式返回的。

查看smarty源码发现display其实是调用的$smarty->fetch(),发现一个$diaplay参数,true时打印页面,false时返回字符串。直接贴源码(...为省略的逻辑代码)

public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, ...)
    {
        ...
        // display or fetch
        if ($display) {
            ...
            echo $_output;
            return;
        } else {
            ...
            return $_output;
        }
    }

所以使用如下语法可以返回页面内容

$smarty->fetch(‘xxx‘);

PHP Smarty 返回页面内容方法

标签:

原文地址:http://my.oschina.net/u/249000/blog/473188

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!