/** * Override getComponent() so we can attach any pending events if the component is getting initialized. * * @param string $id * @param boolean $createIfNull * @return mixed */ public function getComponent($id, $createIfNull = true) { $component = parent::getComponent($id, false); if (!$component && $createIfNull) { $component = parent::getComponent($id, true); $this->_attachEventListeners($id); } return $component; }
/** * Override getComponent() so we can attach any pending events if the component is getting initialized as well as * do some special logic around creating the `craft()->db` application component. * * @param string $id * @param bool $createIfNull * * @return mixed */ public function getComponent($id, $createIfNull = true) { $component = parent::getComponent($id, false); if (!$component && $createIfNull) { if ($id === 'db') { $dbConnection = $this->asa('AppBehavior')->createDbConnection(); $this->setComponent('db', $dbConnection); } $component = parent::getComponent($id, true); $this->_attachEventListeners($id); } return $component; }