Home > Backend Development > PHP Tutorial > PHP Smarty 返回页面内容方法

PHP Smarty 返回页面内容方法

WBOY
Release: 2016-06-20 12:53:34
Original
804 people have browsed it

使用$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;        }    }
Copy after login

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

$smarty->fetch('xxx');
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template