使用布局挂钩后,CodeIgniter Profiler 不再显示
CodeIgniter Profiler no longer displays after use of a layout hook
我刚刚设置了一个布局挂钩来简化我自己的一些工作,但是,我刚刚意识到我的分析器已经消失了。我不太确定我需要做什么才能取回它。
如果我设置 $config['enable_hooks'] = FALSE
探查器会重新出现,但当然会破坏我的布局。我假设我必须在我的钩子上添加一点 class,但我不确定此时在哪里或什么。
class Layout {
public function index()
{
$CI =& get_instance();
$current_output = $CI->output->get_output();
if ($CI->uri->segment(1) == 'admin')
$layout_file = APPPATH . 'views/admin/layout.php';
else
$layout_file = APPPATH . 'views/frontend/layout.php';
$layout = $CI->load->file($layout_file, true);
$mod_output = str_replace("{yield}", $current_output, $layout);
//echo $layout_file;
echo $mod_output;
}
}
当然,我已经在我的控制器中设置了 $this->output->enable_profiler(TRUE);
。
如有任何建议或帮助,我们将不胜感激!
探查器消失的原因是 运行 Output::_display() 函数中探查器的输出对象。
正如 docs 所解释的那样,当您连接到 "display_override" 点时,您会阻止 Output::_display() 被调用。
如果您想在 Layout 挂钩中输出 Profiler,则需要执行以下操作:
class Layout {
public function index()
{
$CI =& get_instance();
$current_output = $CI->output->get_output();
if ($CI->uri->segment(1) == 'admin')
$layout_file = APPPATH . 'views/admin/layout.php';
else
$layout_file = APPPATH . 'views/frontend/layout.php';
$layout = $CI->load->file($layout_file, true);
$mod_output = str_replace("{yield}", $current_output, $layout);
$CI->load->library('profiler');
if ( ! empty($CI->output->_profiler_sections))
{
$CI->profiler->set_sections($CI->output->_profiler_sections);
}
// If the output data contains closing </body> and </html> tags
// we will remove them and add them back after we insert the profile data
if (preg_match("|</body>.*?</html>|is", $output))
{
$mod_output = preg_replace("|</body>.*?</html>|is", '', $mod_output);
$mod_output .= $CI->profiler->run();
$mod_output .= '</body></html>';
}
else
{
$mod_output .= $CI->profiler->run();
}
//echo $layout_file;
echo $mod_output;
}
}
我所做的就是从 Output::_display() 中获取一段代码,处理渲染 Profiler 输出并将其与其余的钩子一起插入。
我刚刚设置了一个布局挂钩来简化我自己的一些工作,但是,我刚刚意识到我的分析器已经消失了。我不太确定我需要做什么才能取回它。
如果我设置 $config['enable_hooks'] = FALSE
探查器会重新出现,但当然会破坏我的布局。我假设我必须在我的钩子上添加一点 class,但我不确定此时在哪里或什么。
class Layout {
public function index()
{
$CI =& get_instance();
$current_output = $CI->output->get_output();
if ($CI->uri->segment(1) == 'admin')
$layout_file = APPPATH . 'views/admin/layout.php';
else
$layout_file = APPPATH . 'views/frontend/layout.php';
$layout = $CI->load->file($layout_file, true);
$mod_output = str_replace("{yield}", $current_output, $layout);
//echo $layout_file;
echo $mod_output;
}
}
当然,我已经在我的控制器中设置了 $this->output->enable_profiler(TRUE);
。
如有任何建议或帮助,我们将不胜感激!
探查器消失的原因是 运行 Output::_display() 函数中探查器的输出对象。
正如 docs 所解释的那样,当您连接到 "display_override" 点时,您会阻止 Output::_display() 被调用。
如果您想在 Layout 挂钩中输出 Profiler,则需要执行以下操作:
class Layout {
public function index()
{
$CI =& get_instance();
$current_output = $CI->output->get_output();
if ($CI->uri->segment(1) == 'admin')
$layout_file = APPPATH . 'views/admin/layout.php';
else
$layout_file = APPPATH . 'views/frontend/layout.php';
$layout = $CI->load->file($layout_file, true);
$mod_output = str_replace("{yield}", $current_output, $layout);
$CI->load->library('profiler');
if ( ! empty($CI->output->_profiler_sections))
{
$CI->profiler->set_sections($CI->output->_profiler_sections);
}
// If the output data contains closing </body> and </html> tags
// we will remove them and add them back after we insert the profile data
if (preg_match("|</body>.*?</html>|is", $output))
{
$mod_output = preg_replace("|</body>.*?</html>|is", '', $mod_output);
$mod_output .= $CI->profiler->run();
$mod_output .= '</body></html>';
}
else
{
$mod_output .= $CI->profiler->run();
}
//echo $layout_file;
echo $mod_output;
}
}
我所做的就是从 Output::_display() 中获取一段代码,处理渲染 Profiler 输出并将其与其余的钩子一起插入。