Skip to content

Commit

Permalink
V1.13
Browse files Browse the repository at this point in the history
完成前台首页最近回复的小部件
  • Loading branch information
michaelweixi committed Nov 15, 2016
1 parent 524c5b5 commit 3fbc7c0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
6 changes: 5 additions & 1 deletion common/models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ public function beforeSave($insert)
else return false;
}


public static function findRecentComments($limit=10)
{
return Comment::find()->where(['status'=>2])->orderBy('create_time DESC')
->limit($limit)->all();
}



Expand Down
4 changes: 3 additions & 1 deletion database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@

源码版本:V1.11 ————— 同上

源码版本:V1.12 ————— 同上
源码版本:V1.12 ————— 同上

源码版本:V1.13 ————— 同上
35 changes: 35 additions & 0 deletions frontend/components/RctReplyWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace frontend\components;

use yii\base\Widget;
use yii\helpers\Html;

class RctReplyWidget extends Widget
{
public $recentComments;

public function init()
{
parent::init();
}

public function run()
{
$commentString='';

foreach ($this->recentComments as $comment)
{
$commentString.='<div class="post">'.
'<div class="title">'.
'<p style="color:#777777;font-style:italic;">'.
nl2br($comment->content).'</p>'.
'<p class="text"> <span class="glyphicon glyphicon-user" aria-hidden="ture">
</span> '.Html::encode($comment->user->username).'</p>'.

'<p style="font-size:8pt;color:bule">
《<a href="'.$comment->post->url.'">'.Html::encode($comment->post->title).'</a>》</p>'.
'<hr></div></div>';
}
return $commentString;
}
}
21 changes: 12 additions & 9 deletions frontend/controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use yii\filters\VerbFilter;

use common\models\Tag;
use common\models\Comment;

/**
* PostController implements the CRUD actions for Post model.
Expand Down Expand Up @@ -38,15 +39,17 @@ public function behaviors()
public function actionIndex()
{
$tags=Tag::findTagWeights();

$searchModel = new PostSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'tags'=>$tags,
]);
$recentComments=Comment::findRecentComments();

$searchModel = new PostSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'tags'=>$tags,
'recentComments'=>$recentComments,
]);
}


Expand Down
5 changes: 4 additions & 1 deletion frontend/views/post/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use yii\grid\GridView;
use yii\widgets\ListView;
use frontend\components\TagsCloudWidget;
use frontend\components\RctReplyWidget;

/* @var $this yii\web\View */
/* @var $searchModel common\models\PostSearch */
Expand Down Expand Up @@ -73,7 +74,9 @@
<li class="list-group-item">
<span class="glyphicon glyphicon-comment" aria-hidden="true"></span> 最新回复
</li>
<li class="list-group-item">最新回复</li>
<li class="list-group-item">
<?= RctReplyWidget::widget(['recentComments'=>$recentComments])?>
</li>
</ul>
</div>

Expand Down

0 comments on commit 3fbc7c0

Please sign in to comment.