Yii2 Bootstrap 3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7 KiB

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug;
12 years ago
use Yii;
use yii\base\View;
use yii\helpers\Html;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Module extends \yii\base\Module
{
public $controllerNamespace = 'yii\debug\controllers';
12 years ago
/**
* @var array|Panel[]
*/
public $panels = array();
12 years ago
public function init()
{
parent::init();
12 years ago
foreach (array_merge($this->corePanels(), $this->panels) as $id => $config) {
$config['id'] = $id;
$this->panels[$id] = Yii::createObject($config);
}
Yii::$app->getLog()->targets['debug'] = new LogTarget($this);
12 years ago
Yii::$app->getView()->on(View::EVENT_END_BODY, array($this, 'renderToolbar'));
}
public function beforeAction($action)
{
Yii::$app->getView()->off(View::EVENT_END_BODY, array($this, 'renderToolbar'));
12 years ago
unset(Yii::$app->getLog()->targets['debug']);
12 years ago
return parent::beforeAction($action);
}
public function renderToolbar($event)
{
/** @var View $view */
$id = 'yii-debug-toolbar';
$url = Yii::$app->getUrlManager()->createUrl('debug/default/toolbar', array(
'tag' => Yii::$app->getLog()->getTag(),
12 years ago
));
$view = $event->sender;
$view->registerJs("yii.debug.load('$id', '$url');");
$view->registerAssetBundle('yii/debug');
echo Html::tag('div', '', array(
'id' => $id,
'style' => 'display: none',
));
}
12 years ago
protected function corePanels()
{
return array(
'config' => array(
'class' => 'yii\debug\panels\ConfigPanel',
),
'request' => array(
'class' => 'yii\debug\panels\RequestPanel',
),
'log' => array(
'class' => 'yii\debug\panels\LogPanel',
),
);
}
12 years ago
}