phuongdev89 / yii2-debug
Yii2 Debug
dev-master
2023-03-09 09:32 UTC
Requires
- php: >=7
- yiisoft/yii2-debug: *
This package is auto-updated.
Last update: 2024-09-09 12:51:06 UTC
README
依赖
在安装此扩展之前必须拥有 phpstorm-protocol
Composer
安装此扩展的首选方式是通过 composer.
运行以下命令之一
php composer.phar require --prefer-dist phuongdev89/yii2-debug "@dev"
或者
"phuongdev89/yii2-debug": "@dev"
将以下内容添加到您的 composer.json
文件的 require 部分。
配置
'modules' => [
'debug' => [
'class' => 'phuongdev89\debug\Module',
],
],
或者
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'phuongdev89\debug\Module',
];
回溯使用
用于查看给定对象的回溯
使用现有的活动记录初始化回溯
示例
if($model->save()) {
Backtrace::init($model);
}
将回溯保存到文件中,格式为 json
示例
$model = new Model;
$model->id = 1;
$model->username = 'test';
if($model->save()) {
Backtrace::init($model)->toFile('@runtime/test.json');
//Output is /runtime/test.json
}
返回 json 格式
示例
if($model->save()) {
$traceJson = Backtrace::init($model)->toJson();
}
输出
[
{
"function": "actionUpdate",
"class": "backend\\controllers\\UserController",
"type": "->"
},
{
"file": "backend/controllers/UserController.php",
"line": 366,
"function": "save",
"class": "common\\models\\User",
"type": "->"
},
{
"file": "/var/www/tribe/common/models/User.php",
"line": 289,
"function": "toJson",
"class": "phuongdev89\\debug\\db\\Backtrace",
"type": "::"
}
]
返回 php 数组格式
示例
if($model->save()) {
$traceJson = Backtrace::init($model)->toArray();
}
输出
[
[
"function" => "actionUpdate",
"class" => "backend\\controllers\\UserController",
"type" => "->"
],
[
"file" => "backend/controllers/UserController.php",
"line" => 366,
"function" => "save",
"class" => "common\\models\\User",
"type" => "->"
],
[
"file" => "/var/www/tribe/common/models/User.php",
"line" => 289,
"function" => "toJson",
"class" => "phuongdev89\\debug\\db\\Backtrace",
"type" => "::"
]
]
自动更新给定列的 json 数据
示例
if($model->save()) {
Backtrace::init($model)->toAttribute('trace');
}