예제 #1
0
 /**
  * @return string
  */
 public function actionCreate()
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $model = new CreateForm();
         if ($model->load(Yii::$app->getRequest()->post(), '')) {
             if ($model->validate()) {
                 $id = Yii::$app->getRequest()->post('topic_id');
                 if ($model->create($id)) {
                     $count = Post::find()->where(['topic_id' => $model->getTopic()->id])->count();
                     $data['post'] = \post\widgets\Post::widget(['post' => $model->getPost(), 'count' => $count]);
                     $data['post_id'] = $model->getPost()->getPrimaryKey();
                     $data['page'] = $this->getPageByPost($model->getPost());
                     return $data;
                 }
             } else {
                 return ['errors' => $model->getFirstErrors()];
             }
         }
     }
     throw new NotFoundHttpException();
 }
예제 #2
0
<?php

/* @var \post\models\Post $model */
/* @var \yii\widgets\ListView $widget */
/* @var \yii\data\ActiveDataProvider $dataProvider */
/* @var integer $index */
/* @var integer $key */
use yii\helpers\Url;
use post\widgets\Post;
$dataProvider = $widget->dataProvider;
$count = $dataProvider->pagination->page * 15 + $index + 1;
echo Post::widget(['post' => $model, 'count' => $count]);
if ($model->topic->first_post_id == $key) {
    ?>
<div class="topic-tags">
    <span class="fa fa-tags topic-tags-fa"></span>
    <?php 
    foreach ($model->topic->tags as $tag) {
        ?>
    <a class="tag-url" href="<?php 
        echo Url::toRoute(['/topic/default/list', 'name' => $tag->name]);
        ?>
"><?php 
        echo $tag->name;
        ?>
</a>
    <?php 
    }
    ?>
</div>
<?php