Home > Backend Development > PHP Tutorial > joomla - php 在缓冲区引入文件的目的

joomla - php 在缓冲区引入文件的目的

WBOY
Release: 2016-06-06 20:26:30
Original
1398 people have browsed it

<code>ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();</code>
Copy after login
Copy after login

上述代码的意义在哪里?

回复内容:

<code>ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();</code>
Copy after login
Copy after login

上述代码的意义在哪里?

拿控制器中使用render函数载入视图来说:

<code><?php function render($template, array $data = array()) {
    global $app;
    ob_start();
    require APP_ROOT.'themes/'.$app['theme'].'/'.$template;
    $view = ob_get_contents();
    ob_end_clean();
    return $view;
}
$view = render('post.php');
// 后续可以对视图内容进行一些操作,比如生成静态文件,或者替换一些内容,然后输出:
echo $view;</code></code>
Copy after login

可以阻止输出

你想象一下这个configuration.php里面有一行echo,因为开了缓冲区,它会写入缓冲区而不是客户端浏览器
然后执行完require之后,终止缓冲区并清除缓冲区内容,然后也就不会有任何输出出来了

Related labels:
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