Yii2Debug::init PHP Method

init() public method

Generate unique tag for page. Attach panels, log watcher. Register scripts for printing debug panel.
public init ( )
    public function init()
    {
        parent::init();
        if (!$this->enabled) {
            return;
        }
        // Do not run on console.
        if (Yii::app() instanceof CConsoleApplication) {
            return;
        }
        Yii::setPathOfAlias('yii2-debug', dirname(__FILE__));
        Yii::app()->setImport(array('yii2-debug.*', 'yii2-debug.panels.*'));
        if ($this->logPath === null) {
            $this->logPath = Yii::app()->getRuntimePath() . '/debug';
        }
        $panels = array();
        foreach (CMap::mergeArray($this->corePanels(), $this->panels) as $id => $config) {
            if (!isset($config['highlightCode'])) {
                $config['highlightCode'] = $this->highlightCode;
            }
            $panels[$id] = Yii::createComponent($config, $this, $id);
        }
        $this->panels = $panels;
        Yii::app()->setModules(array($this->moduleId => array('class' => 'Yii2DebugModule', 'owner' => $this)));
        if ($this->internalUrls && Yii::app()->getUrlManager()->urlFormat == 'path') {
            $rules = array();
            foreach ($this->coreUrlRules() as $key => $value) {
                $rules[$this->moduleId . '/' . $key] = $this->moduleId . '/' . $value;
            }
            Yii::app()->getUrlManager()->addRules($rules, false);
        }
        Yii::app()->attachEventHandler('onEndRequest', array($this, 'onEndRequest'));
        $this->initToolbar();
    }

Usage Example

Exemplo n.º 1
0
 public function init()
 {
     if ($this->enabled) {
         $this->enabled = Yii::app()->user->checkAccess(DaWebUser::ROLE_DEV);
     }
     parent::init();
 }