-
Notifications
You must be signed in to change notification settings - Fork 3
/
News.php
76 lines (72 loc) · 2.07 KB
/
News.php
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
<?php
namespace lav45\behaviors\tests\models;
use yii\behaviors\AttributeBehavior;
use yii\db\ActiveRecord;
use lav45\behaviors\VirtualAttributesTrait;
use lav45\behaviors\SerializeProxyBehavior;
use lav45\behaviors\SerializeBehavior;
/**
* Class News
* @package lav45\behaviors\tests\models
*
* @property integer $id
* @property string $title
* @property string $_data
* @property string $_tags
* @property string $_options
*
* Virtual attributes
* ---------------------------
* @property string $description
* @property array $meta
* @property string $meta_keywords
* @property bool $is_active
* @property int $defaultValue
* @property int $defaultFunc
*
* @property array $tags
* @property array $options
*/
class News extends ActiveRecord
{
use VirtualAttributesTrait;
public function behaviors()
{
return [
'serialize' => [
'class' => SerializeBehavior::class,
'storageAttribute' => '_data',
'attributes' => [
'description',
'meta' => [
'keywords' => null,
'description' => null,
],
'meta_keywords',
'is_active' => true,
'defaultValue' => 1,
'defaultFunc' => function() {
return $this->id;
}
]
],
'serializeProxy' => [
'class' => SerializeProxyBehavior::class,
'attributes' => [
'tags' => '_tags',
'options' => '_options',
]
],
[
'class' => AttributeBehavior::class,
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'meta_keywords',
ActiveRecord::EVENT_BEFORE_UPDATE => 'meta_keywords',
],
'value' => function () {
return $this->meta['keywords'];
}
]
];
}
}