Module.php 1.21 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7 8 9
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\debug;

Qiang Xue committed
10 11 12 13
use Yii;
use yii\base\View;
use yii\helpers\Html;

Qiang Xue committed
14 15 16 17 18 19 20
/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class Module extends \yii\base\Module
{
	public $controllerNamespace = 'yii\debug\controllers';
Qiang Xue committed
21
	public $panels;
Qiang Xue committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

	public function init()
	{
		parent::init();
		Yii::$app->log->targets['debug'] = new LogTarget;
		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'));
		unset(Yii::$app->log->targets['debug']);
		return parent::beforeAction($action);
	}

	public function renderToolbar($event)
	{
		/** @var View $view */
		$id = 'yii-debug-toolbar';
		$url = Yii::$app->getUrlManager()->createUrl('debug/default/toolbar', array(
Qiang Xue committed
42
			'tag' => Yii::$app->getLog()->getTag(),
Qiang Xue committed
43 44 45 46 47 48 49 50 51
		));
		$view = $event->sender;
		$view->registerJs("yii.debug.load('$id', '$url');");
		$view->registerAssetBundle('yii/debug');
		echo Html::tag('div', '', array(
			'id' => $id,
			'style' => 'display: none',
		));
	}
resurtm committed
52
}