关于 Codeigniter 2.2 中的片段源代码的问题


Questions about the fragment source code in Codeigniter 2.2

我正在尝试阅读CI 2的源代码,对此感到困惑核心/加载器类的视图方法

        /*
     * Flush the buffer... or buff the flusher?
     *
     * In order to permit views to be nested within
     * other views, we need to flush the content back out whenever
     * we are beyond the first level of output buffering so that
     * it can be seen and included properly by the first included
     * template and any subsequent ones. Oy!
     *
     */
    if (ob_get_level() > $this->_ci_ob_level + 1)
    {
        ob_end_flush();
    }
    else
    {
        $_ci_CI->output->append_output(ob_get_contents());
        @ob_end_clean();
    }

我无法理解这个片段的重点,

第一:代码注释说它适用于嵌套视图,但我认为在以下情况下它会被刷新:

...
$this->load->view('section_a');
$this->load->view('section_b');
...

每次我们运行 view 方法时,都会打开一个缓冲区,所以如果我们加载两个视图,即使它们没有嵌套,第一个也会被刷新,对吗?

2nd:为什么我们需要立即刷新最早的缓冲区?

由于它们最终会自动刷新,实际上我发现最终渲染方法中没有'ob_end_flush',Output->_display(),这意味着CI仍然依赖于自动刷新功能,对吧?

3rd:为什么条件是当前ob级别大于默认级别+1?

如果我加载两个视图,第二个视图将触发刷新,对吗?

第四:如果在这里手动刷新视图,它是否仍会通过 Output->_display() 进行调整?

尽力把话说清楚,希望你能帮到我。谢谢。

每次我们运行 view 方法时,都会打开一个缓冲区,所以如果我们 加载两个视图,即使它们没有嵌套,第一个视图也是 脸红了,是吗?

不。仅当加载一个视图文件时调用另一个对$this->load->view()的调用时,才会发生这种情况。

当连续调用时,如示例中所示,每个都将在加载时追加到输出类。

2nd:为什么我们需要立即刷新最早的缓冲区?

刷新它的不是最早的缓冲区,

而是当前缓冲区,它被刷新到较早的缓冲区中。 输出缓冲区是堆叠的,而不是并行的。

3rd:为什么条件是当前ob级别大于默认级别+1?

我认为这已经得到了回答。 当ob_get_level() > $this->_ci_ob_level + 1时,我们尝试在当前正在加载的视图中再次调用load->view()

第四:如果在这里手动刷新视图,它是否仍会通过 Output->_display() 进行调整?

"这里"在哪里?但我认为答案是否定的。