public function setEventHandlers() { // Set eventhandlers for the 'Menu' model Event::on(Menu::className(), ActiveRecord::EVENT_AFTER_DELETE, function ($event) { // Delete the children if (!$event->sender->deleteChildren()) { throw new \yii\base\Exception(Yii::t('app', 'There was an error while deleting this item')); } }); // Set eventhandlers for the 'MenuItem' model Event::on(MenuItem::className(), ActiveRecord::EVENT_AFTER_DELETE, function ($event) { // Delete the children if (!$event->sender->deleteChildren()) { throw new \yii\base\Exception(Yii::t('app', 'There was an error while deleting this item')); } }); }
/** * @return \yii\db\ActiveQuery */ public function getMenu() { return $this->hasOne(Menu::className(), ['id' => 'menu_id']); }
/** * @return \yii\db\ActiveQuery */ public function getMenu() { if (Yii::$app->getModule('pages')->enableMenu) { return $this->hasOne(\infoweb\menu\models\Menu::className(), ['id' => 'menu_id']); } else { return null; } }