内容简介:实验功能我们已经努力使事情正常工作,但是可能会出现错误,导致和/或收取此功能所需的资产。如果您在使用过程中发生过事故,由于将Luthier CI与这个出色的工具集成在一起,您可以将
调试 Debug
实验功能
我们已经努力使事情正常工作,但是可能会出现错误,导致和/或收取此功能所需的资产。如果您在使用过程中发生过事故, 请通知我们。
内容 Contents
介绍 Introduction
由于将Luthier CI与这个出色的 工具 集成在一起,您可以将 PHP Debug Bar 添加到您的应用程序中。
激活 Activation
要激活此功能(默认情况下已禁用),请转到您的 application/config/hooks.php 文件并替换:
<?php
# application/config/hooks.php
defined('BASEPATH') OR exit('No direct script access allowed');
// (...)
$hook = Luthier\Hook::getHooks();
附:
<?php
# application/config/hooks.php
defined('BASEPATH') OR exit('No direct script access allowed');
// (...)
$hook = Luthier\Hook::getHooks(
[
'modules' => ['debug']
]
);
您应该在窗口底部看到调试栏:
调试消息 Debug messages
要添加调试消息,请使用该类的 log() 静态方法 Luthier\Debug :
# use Luthier\Debug; Debug::log($variable, $type, $dataCollector);
$variable 要调试的变量在哪里,并且 $type 是消息的类型,可以是 'info' , 'warning' 或 'error' .
例:
<?php
# application/controllers/TestController.php
use Luthier\Debug;
defined('BASEPATH') OR exit('No direct script access allowed');
class TestController extends CI_Controller
{
public function index()
{
Debug::log('Welcome to Luthier-CI ' . LUTHIER_CI_VERSION . '!');
Debug::log('Hello world!','info');
Debug::log('This is a warning, watch out!','warning');
Debug::log('Oh snap! an error was occurred!','error');
$this->load->view('welcome_message');
}
}
结果如下:
可选 $dataCollector 参数是将存储消息的 data collector 的名称
Debug::log('Custom data collector','error','my_custom_data_collector');
如果需要存储要在下一个请求中显示的消息(例如,在提交表单后),请使用该 logFlash() 方法,其语法与 log() 静态方法相同:
Debug::logFlash('Hey! this will be available in the next request','info');
在生产环境中取消激活
如果将应用程序的环境设置 production 为此功能将自动禁用,并且将忽略任何调试代码
要求输出缓冲区中有数据
Luthier CI 在输出缓冲区中添加PHP Debug Bar代码,然后由 output CodeIgniter库处理并发送到浏览器。因此,必须至少使用一次函数 $this->load-> view() 或明确定义输出缓冲区才能工作。该 echo 语句不产生任何内部输出缓冲器。此外,使用函数停止执行脚本 die 或 exit 将阻止显示 PHP 调试栏。
添加您自己的数据收集器 ( Add your own data collectors )
可以添加自己的数据收集器并在其中存储消息。要将数据收集器添加到PHP Debug Bar实例,请使用 addCollector() static方法:
# use Luthier\Debug; Debug::addCollector(new MyCollector());
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- iOS常用调试方法:断点调试
- 断点调试和日志调试之间的平衡点:函数计算调试之 Python 篇
- .NET高级调试系列-Windbg调试入门篇
- VisualStudio 通过外部调试方法快速调试库代码
- GDB 调试 Mysql 实战(二)GDB 调试打印
- 使用gdb调试工具上手调试php和swoole源码
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。