LandingController.php
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace frontend\controllers;
use artbox\core\components\SeoComponent;
use artbox\core\models\Language;
use artbox\core\models\Alias;
use artbox\core\models\PageLang;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\base\ViewNotFoundException;
use Yii;
/**
* Class LandingController
*
* @package frontend\controllers
*/
class LandingController extends Controller
{
public function actionView($id)
{
// // Sets meta-tags on page, previously added through the admin panel -> "SEO page || route set as json with index ¯\_(ツ)_/¯ -> {"0":"komplekty"}
$seo = \Yii::$app->get('seo');
$language = Language::getCurrent();
$alias = Alias::findRoute([ $id ], $language);
if( empty($alias) ) throw new NotFoundHttpException();
$seo->setAlias($alias);
$model = $this->findModel($alias->id, $language->id);
return $this->renderPartial(
'view',
[
'model' => $model,
]
);
}
protected function findModel($id, $lang)
{
/**
* @var Page $model
*/
$model = PageLang::find()
->where(
[
'alias_id' => $id,
'language_id' => $lang
]
)
->one();
if ( empty($model) ) throw new NotFoundHttpException('Model not found');
return $model;
}
}