0

В CodeIgniter для вывода на экран шаблона используется конструкция $this->load->view('шаблон');

Где находится этот метод view? Хотел посмотреть, как там реализован вывод шаблона. Сразу ли там инклюд или буфер. Спасибо

1 ответ 1

1

Метод находится в классе Loader:443 и выглядит так:

public function view($view, $vars = array(), $return = FALSE)
{
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}

А на ваш вопрос отвечает метод Loader::_ci_load(..):

protected function _ci_load($_ci_data)
{
    // сократил :)

    /*
     * Buffer the output
     *
     * We buffer the output for two reasons:
     * 1. Speed. You get a significant speed boost.
     * 2. So that the final rendered template can be
     * post-processed by the output class.  Why do we
     * need post processing?  For one thing, in order to
     * show the elapsed page load time.  Unless we
     * can intercept the content right before it's sent to
     * the browser and then stop the timer it won't be accurate.
     */
    ob_start();

    // ещё сократил

    // Return the file data if requested
    if ($_ci_return === TRUE)
    {
        $buffer = ob_get_contents();
        @ob_end_clean();
        return $buffer;
    }

    /*
     * 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();
    }
}

Чтобы понять, почему Loader см CI_Controller:78

7
  • Там вроде нету инклюда шаблона или я его не вижу?) 8 июл 2015 в 11:41
  • Есть, но я сократил много, смотрите Loader.php:910,914
    – xEdelweiss
    8 июл 2015 в 11:45
  • в kohana есть такая конструкция: $this->template->content = $content; свойство content в свойстве template. Как это??? 8 июл 2015 в 13:03
  • Так же как и тут - ничто не мешает свойству быть объектом со своими свойствами.
    – xEdelweiss
    8 июл 2015 в 13:07
  • внутренние шаблоны выводятся буфером. не могу понять, как выводить основной шаблон (базовый) сразу инклюд? или тоже буфер 8 июл 2015 в 13:09

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.