Skip to content

Commit c31ff9d

Browse files
authored
add PageMetaTagsFilter
1 parent 04593d8 commit c31ff9d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* @author Dmytro Karpovych
4+
* @copyright 2016 NRE
5+
*/
6+
7+
namespace nullref\cms\components;
8+
9+
10+
use nullref\cms\models\Page;
11+
use Yii;
12+
use yii\base\ActionFilter;
13+
14+
class PageMetaTagsFilter extends ActionFilter
15+
{
16+
public function beforeAction($action)
17+
{
18+
if (!Yii::$app->request->isAjax) {
19+
$url = '/' . Yii::$app->request->pathInfo;
20+
/** @var Page $page */
21+
$page = Page::find()->byRoute($url)->one();
22+
if ($page !== null) {
23+
$view = $action->controller->view;
24+
$page->registerMetaTags($view);
25+
$view->params['cms.page'] = $page;
26+
}
27+
}
28+
return parent::beforeAction($action);
29+
}
30+
}

0 commit comments

Comments
 (0)