/
pashko
/
siec
Обзор
Документация
Войти
/
pashko
/
siec
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
common/models/Blog.php
114 строк
3 KB
pash lenovo
news page with server API
29 окт 2019, 12:42
29 окт 2019, 12:42
5575db1
Код
Авторство
О чём код?
<?php namespace common\models; use yii\behaviors\TimestampBehavior; use yii\db\ActiveRecord; /** * This is the model class for table "blog". * * @property int $id * @property string $name * @property string $short_text * @property string $text * @property int $sort * @property string $active * @property string $slug */ class Blog extends ActiveRecord { function behaviors() { return [ 'images' => [ 'class' => 'dvizh\gallery\behaviors\AttachImages', 'mode' => 'gallery', ], 'slug' => [ 'class' => 'Zelenin\yii\behaviors\Slug', ], 'seo' => [ 'class' => 'dvizh\seo\behaviors\SeoFields', ], 'toServices' => [ 'class' => 'voskobovich\manytomany\ManyToManyBehavior', 'relations' => [ 'service_ids' => 'services', ], ], 'timestamp' => [ 'class' => TimestampBehavior::className(), 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; } /** * {@inheritdoc} */ public static function tableName() { return 'blog'; } /** * {@inheritdoc} */ public function rules() { return [ [['name'], 'required'], [['text', 'active', 'on_index', 'button_text', 'banner_form_title', 'show_cases', 'show_calculator'], 'string'], [['sort', 'author_id', 'form_type_id', 'banner_bg_id'], 'integer'], [['name', 'short_text', 'slug'], 'string', 'max' => 255], [['service_ids'], 'each', 'rule' => ['integer']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'name' => 'Name', 'short_text' => 'Short Text', 'text' => 'Text', 'sort' => 'Sort', 'active' => 'Active', 'slug' => 'Slug', 'author_id' => 'Автор', 'on_index' => 'Показывать на главной', 'button_text' => 'Текс на кнопке баннера', 'form_type_id' => 'Тип формы баннера', 'banner_form_title' => 'Текст над формой баннера', 'show_cases' => 'Показывать блок с кейсами?', 'show_calculator' => 'Показать калькулятор' ]; } public function getBlogs() { return $this->hasMany(Blog::className(), ['id' => 'blog_id']) ->viaTable('{{%blog_to_blog}}', ['current_id' => 'id']); } public function getAuthor() { return $this->hasOne(Author::className(), ['id' => 'author_id']); } public function getServices() { return $this->hasMany(Service::className(), ['id' => 'service_id']) ->viaTable('{{%blog_to_service}}', ['blog_id' => 'id']); } public function getBannerBg() { return $this->hasOne(BannerBg::className(), ['id' => 'banner_bg_id']); } }