/** * @param Page $page */ public static function setCurrentPage(Page &$page) { static::$currentPage = $page; }
/** * Gets a page by the url. * @param string $url * @return bool|null|static */ public static function getCurrentPage($url = '') { if (static::$currentPage !== false) { return static::$currentPage; } /** @var static $model */ $model = static::find()->where(['url' => preg_replace('/[\\/]{2,}/', '/', '/' . $url . '/'), 'visible' => static::VISIBLE_YES])->orderBy('id DESC')->one(); if (!$model) { return static::$currentPage = null; } if ($model->layout) { Yii::$app->controller->layout = $model->layout; } Yii::$app->view->title = $model->page_title; Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $model->page_description]); Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $model->page_keywords]); return static::$currentPage = $model; }