/** * @inheritdoc */ public function init() { parent::init(); if ($this->isNewRecord && $this->className() == Post::className()) { $this->published_at = time(); } $this->on(self::EVENT_BEFORE_UPDATE, [$this, 'updateRevision']); $this->on(self::EVENT_AFTER_UPDATE, [$this, 'saveTags']); $this->on(self::EVENT_AFTER_INSERT, [$this, 'saveTags']); }
/** * @return \yii\db\ActiveQuery */ public function getPosts() { return $this->hasMany(Post::className(), ['category_id' => 'id']); }
<?php echo Html::a(Yii::t('yee', 'Add New'), ['/post/default/create'], ['class' => 'btn btn-sm btn-primary']); ?> <?php echo Html::a(Yii::t('yee/media', 'Categories'), ['/post/category/index'], ['class' => 'btn btn-sm btn-primary']); ?> </div> </div> <div class="panel panel-default"> <div class="panel-body"> <div class="row"> <div class="col-sm-6"> <?php echo GridQuickLinks::widget(['model' => Post::className(), 'searchModel' => $searchModel, 'labels' => ['all' => Yii::t('yee', 'All'), 'active' => Yii::t('yee', 'Published'), 'inactive' => Yii::t('yee', 'Pending')]]); ?> </div> <div class="col-sm-6 text-right"> <?php echo GridPageSize::widget(['pjaxId' => 'post-grid-pjax']); ?> </div> </div> <?php Pjax::begin(['id' => 'post-grid-pjax']); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getPosts() { return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable('{{%post_tag_post}}', ['tag_id' => 'id']); }
<?php /* @var $this yii\web\View */ use yeesoft\comments\widgets\Comments; use yeesoft\post\models\Post; /* @var $post yeesoft\post\models\Post */ $this->title = $post->title; $this->params['breadcrumbs'][] = $post->title; ?> <?php echo $this->render('/items/post.php', ['post' => $post]); ?> <?php if ($post->comment_status == Post::COMMENT_STATUS_OPEN) { ?> <?php echo Comments::widget(['model' => Post::className(), 'model_id' => $post->id]); }