Page.php
2.7 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace common\models;
use Yii;
use common\models\PageLang;
/**
* This is the model class for table "page".
*
* @property integer $page_id
* @property string $date_add
* @property integer $template_id
* @property integer $image_id
* @property integer $show
*/
class Page extends \yii\db\ActiveRecord
{
var $data;
//public $title;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'page';
}
// ==== DATA PAGE LANG ====
public function getData()
{
$this->data = PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => 1])->one();
}
public function getDataByKey($key)
{
if (! $this->data)
{
$this->getData();
}
return isset ($this->data[$key]) ? $this->data[$key] : 'NO FIELD';
}
// ==== DATA PAGE LANG FIELD ====
public function getExtraField($key)
{
return PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => 1])->one()->$key;
}
public function getTitle()
{
return $this->getDataByKey('title');
}
public function getMeta_title()
{
return $this->getDataByKey('meta_title');
}
public function getMeta_description()
{
return $this->getDataByKey('meta_description');
}
public function getText()
{
return $this->getDataByKey('text');
}
public function getPage_alias()
{
return $this->getDataByKey('page_alias');
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['date_add', 'template_id', 'image_id', 'show'], 'required'],
[['date_add'], 'safe'],
[['template_id', 'image_id', 'show'], 'integer']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'page_id' => Yii::t('field', 'page'),
'date_add' => Yii::t('field', 'date_add'),
'template_id' => Yii::t('field', 'template'),
'image_id' => Yii::t('field', 'image'),
'show' => Yii::t('field', 'show'),
'title' => Yii::t('field', 'title'),
'meta_title' => Yii::t('field', 'meta_title'),
'meta_description' => Yii::t('field', 'meta_description'),
'text' => Yii::t('field', 'text'),
'page_alias' => Yii::t('field', 'page_alias'),
'lang_id' => Yii::t('field', 'lang_id'),
];
}
/*
public function getPage()
{
return $this->hasMany(PageLang::className(), ['page_id' => 'page_id']);
}
*/
}