/** * @param string $route * @return array */ public function getMeta($route) { $cache = Yii::$app->{$this->cache}; $cacheId = $this->componentId . '|routes|' . $route; $aMeta = $cache->get($cacheId); if ($aMeta) { return $aMeta; } $oMeta = new Meta(); $oMeta->setRoute($route); $aMeta = []; $model = Meta::findOne(['hash' => $oMeta->hash]); if (!empty($model)) { $info = $model->toArray(); foreach ($info as $idData => $data) { if (!empty($data)) { $aMeta[$idData] = $data; } } } else { // Si no existe la entrada con esa ruta la creamos $oMeta->save(); } $oTagDependency = new \yii\caching\TagDependency(['tags' => self::CACHE_TAG]); $cache->set($cacheId, $aMeta, $this->cacheDuration, $oTagDependency); return $aMeta; }
/** * Finds the MetaBase model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MetaBase the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Meta::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }