首頁  >  文章  >  後端開發  >  PHP Smarty 返回页面内容方法

PHP Smarty 返回页面内容方法

WBOY
WBOY原創
2016-06-20 12:53:34708瀏覽

使用$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');
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn