public function run() { $connection = Yii::$app->db; $commentList = $connection->createCommand('SELECT * FROM {{%comment}} WHERE table_id=:tableId AND table_name=:tableName')->bindValues([':tableId' => $this->tableId, ':tableName' => $this->tableName])->queryAll(); $newComment = new \app\models\Comment(); if ($newComment->load(Yii::$app->request->post())) { $newComment->table_id = $this->tableId; $newComment->table_name = $this->tableName; if ($newComment->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Create successfully.')); return Yii::$app->getResponse()->refresh(); } else { print_r($newComment->getErrors()); } } return $this->render('comment', ['commentList' => $commentList, 'newComment' => $newComment]); }
$this->params['breadcrumbs'][] = $this->title; ?> <div class="comment-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', '创建评论', ['modelClass' => 'Comment']), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'content:ntext', ['attribute' => 'status', 'label' => '评论状态', 'value' => function ($data) { if (!empty($data->status)) { return '审核通过'; } else { return '等待审核'; } }, 'filter' => [0 => '等待审核', 1 => '审核通过']], 'author_name', ['attribute' => 'post_id', 'label' => '文章ID', 'filter' => yii\helpers\ArrayHelper::map(app\models\Comment::find()->orderBy('id')->asArray()->all(), 'post_id', 'post_id')], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function get9() { // get comments $request = Yii::$app->request; $page = $request->get('page', 1); $num = $request->get('num', 10); $id = $request->get('id'); $model = new \app\models\Comment(); $arr = $model->get($page, $num, $id); $back = ''; if (count($arr) > 0) { foreach ($arr as $key => $val) { $back .= CommentsWidget::widget(['model' => $val]); } } else { $back .= "\n <div>\n <p>哎呀,木有评论啦~\\(≧▽≦)/~啦啦啦</p>\n <img src='http://img.baidu.com/hi/jx2/j_0005.gif' />\n <p>Would you like leaving a comment?</p>\n <a href='javascript:;' onclick=\"\$(this).parents('.one-blog').find('.bottom-zujian').slideDown()\">OK,Comment now</a>\n </div>\n "; } $this->back['info'] = $back; $this->back['info2'] = $arr; }
echo $model->description; ?> </div> </td> </tr> <tr> <td>Course</td> <td><?php echo app\models\Course::findOne($model->course_id)->name; ?> </td> </tr> <tr> <td>Comments</td> <td><?php echo count(app\models\Comment::findAll(['video_id' => $model->id])); ?> </td> </tr> <tr> <td>Uploaded By</td> <td><?php echo app\components\OvcUser::getUserFullName($model->user_id); ?> </td> </tr> <tr> <td>Created on</td> <td><?php echo app\components\OvcUtility::ovcDateFormat($model->created_at); ?>