1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zacksleo\yii2\cms\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\behaviors\TimestampBehavior; |
7
|
|
|
use yii\helpers\Url; |
8
|
|
|
use nemmo\attachments\models\File; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This is the model class for table "{{%page}}". |
12
|
|
|
* |
13
|
|
|
* @property integer $id |
14
|
|
|
* @property string $title |
15
|
|
|
* @property string $slug |
16
|
|
|
* @property integer $status |
17
|
|
|
* @property string $content |
18
|
|
|
* @property integer $created_at |
19
|
|
|
* @property integer $updated_at |
20
|
|
|
*/ |
21
|
|
|
class Page extends \yii\db\ActiveRecord |
22
|
|
|
{ |
23
|
|
|
const STATUS_INACTIVE = 0; |
24
|
|
|
const STATUS_ACTIVE = 1; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritdoc |
28
|
|
|
*/ |
29
|
1 |
|
public static function tableName() |
30
|
|
|
{ |
31
|
1 |
|
return '{{%page}}'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
1 |
|
public function rules() |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
1 |
|
[['title', 'slug'], 'required'], |
41
|
1 |
|
[['status', 'created_at', 'updated_at'], 'integer'], |
42
|
1 |
|
[['content'], 'string'], |
43
|
1 |
|
[['title', 'slug'], 'string', 'max' => 255], |
44
|
1 |
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritdoc |
49
|
|
|
*/ |
50
|
|
|
public function attributeLabels() |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
|
|
'id' => 'ID', |
54
|
|
|
'title' => '标题', |
55
|
|
|
'slug' => '别名', |
56
|
|
|
'status' => '状态', |
57
|
|
|
'content' => '内容', |
58
|
|
|
'created_at' => '创建时间', |
59
|
|
|
'updated_at' => '更新时间', |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritdoc |
65
|
|
|
*/ |
66
|
1 |
|
public function behaviors() |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
|
|
'timestamp' => [ |
70
|
1 |
|
'class' => TimestampBehavior::className(), |
|
|
|
|
71
|
1 |
|
], |
72
|
|
|
'fileBehavior' => [ |
73
|
1 |
|
'class' => \nemmo\attachments\behaviors\FileBehavior::className() |
|
|
|
|
74
|
1 |
|
], |
75
|
1 |
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
public static function getStatusList() |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
1 |
|
self::STATUS_INACTIVE => '隐藏', |
82
|
1 |
|
self::STATUS_ACTIVE => '显示', |
83
|
1 |
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getUrl() |
87
|
|
|
{ |
88
|
|
|
return Url::to(['page/view', 'slug' => $this->slug]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getImage() |
92
|
|
|
{ |
93
|
|
|
if ($this->files && $this->files[0] instanceof File) { |
|
|
|
|
94
|
|
|
return $this->files[0]->getUrl(); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
return 'https://ws1.sinaimg.cn/large/a76d6e45gy1fj5d3ckxgej205x05vaa4.jpg'; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.