/** * Finds the WidgetMenu model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return WidgetMenu the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = WidgetMenu::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function init() { $cacheKey = [WidgetMenu::className(), $this->key]; $this->items = Yii::$app->cache->get($cacheKey); if ($this->items === false) { if (!($model = WidgetMenu::findOne(['key' => $this->key, 'status' => WidgetMenu::STATUS_ACTIVE]))) { throw new InvalidConfigException(); } $this->items = json_decode($model->items, true); Yii::$app->cache->set($cacheKey, $this->items, 60 * 60 * 24); } }
public static function getMenuLinks($key, $additionalLinks) { if (!($model = WidgetMenu::findOne(['key' => $key, 'status' => WidgetMenu::STATUS_ACTIVE]))) { throw new EmptyMenuItemsException(); } $links = array(); foreach ($model->items as $item) { if (WidgetMenuItem::STATUS_ACTIVE == $item->active && !empty($item->name) && $item->url) { $links[] = ['label' => $item->name, 'url' => [$item->url]]; } } if (!empty($additionalLinks) && is_array($additionalLinks)) { $links = array_merge($links, $additionalLinks); } return $links; }