common/models/Page.php
<?php
/*
* This file is part of the HomeFinanceV2 project.
*
* (c) Rafalsky.com <http://github.com/Rafalsky/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace common\models;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
* This is the model class for table "page".
*
* @property integer $id
* @property string $slug
* @property string $title
* @property string $body
* @property string $view
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*/
class Page extends ActiveRecord
{
const STATUS_DRAFT = 0;
const STATUS_PUBLISHED = 1;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%page}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
'slug' => [
'class' => SluggableBehavior::className(),
'attribute' => 'title',
'ensureUnique' => true,
'immutable' => true
]
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title', 'body'], 'required'],
[['body'], 'string'],
[['status'], 'integer'],
[['slug'], 'unique'],
[['slug'], 'string', 'max' => 2048],
[['title'], 'string', 'max' => 512],
[['view'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => \Yii::t('common', 'ID'),
'slug' => \Yii::t('common', 'Slug'),
'title' => \Yii::t('common', 'Title'),
'body' => \Yii::t('common', 'Body'),
'view' => \Yii::t('common', 'Page View'),
'status' => \Yii::t('common', 'Active'),
'created_at' => \Yii::t('common', 'Created At'),
'updated_at' => \Yii::t('common', 'Updated At'),
];
}
}