コード例 #1
0
ファイル: Humour.php プロジェクト: sayi21cn/yt-for-coding
 public function search($params)
 {
     $query = Humour::find();
     $queryParams = Yii::$app->request->getQueryParams();
     $sort = trim(isset($queryParams['sort']) ? $queryParams['sort'] : 'update_time');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ["{$sort}" => SORT_DESC]]]);
     /*自定义处理classify存在情况下的搜索*/
     if (isset($params['classify']) && !empty($params['classify'])) {
         $this->classify = trim(trim($params['classify']));
     } elseif (isset($params['tags']) && !empty($params['tags'])) {
         $this->tags = trim(trim($params['tags']));
     } else {
         if (!($this->load($params) && $this->validate())) {
             return $dataProvider;
         }
     }
     /*********END*************************/
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'author_id' => $this->author_id, 'viewcount' => $this->viewcount, 'up' => $this->up, 'classify' => $this->classify]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'describe', $this->describe])->andFilterWhere(['like', 'tags', $this->tags]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * Creates a new comment.
  * This method attempts to create a new comment based on the user input.
  * If the comment is successfully created, the browser will be redirected
  * to show the created comment.
  * @param News the news that the new comment belongs to
  * @return Comment the comment instance
  */
 protected function newComment($model)
 {
     $comment = new Comment();
     if ($comment->load(Yii::$app->request->post())) {
         /**验证通过***/
         $comment->attributes = $_POST['Comment'];
         if (Yii::$app->user->isGuest) {
             return $comment;
         } else {
             $comment->author_id = Yii::$app->user->id;
             //评论者的id
             $comment->author_name = Yii::$app->user->getIdentity()->username;
             //评论者的名称
             $comment->create_time = date("Y-m-d H:i:s", time());
             if (Yii::$app->user->getIdentity()->role == 1) {
                 $comment->status = 1;
             } else {
                 $comment->status = 2;
             }
             //待审核
             //$comment->post_id   = $model->id;//文章id
             $comment->user_id = $model->author_id;
             //文章作者id
             $comment->classify_type = Humour::getClassName();
             //分类
             $comment->comment_parent_id = '0';
         }
         if ($comment->author_id === '') {
             Yii::$app->Session->setFlash('commentSubmitted', '请先登录');
             $this->refresh();
             exit;
         }
         $comment->content = $_POST['Comment']['content'];
         if ($model->addComment($comment)) {
             if ($comment->status == Comment::STATUS_PENDING) {
                 Yii::$app->Session->setFlash('commentSubmitted', '评论会在审核通过后显示。');
             }
             $this->refresh();
         }
     }
     return $comment;
 }
コード例 #3
0
use app\models\Humour;
use app\models\Tag;
/**
 * @var \yii\web\View $this
 * @var \yii\gii\Generator[] $generators
 * @var \yii\gii\Generator $activeGenerator
 * @var string $content
 */
//$activeGenerator = Yii::$app->controller->generator;
$activeGenerator = isset($_GET['id']) ? $_GET['id'] : '1';
/***分类总数****/
$category = Yii::$app->controller->category();
/**分类名称获取 继承自BaseModel**/
$humourClassify = Humour::humourClassify();
/*热门文章*/
$hotPosts = Humour::getHotPosts();
/*热门标签*/
$tags = Tag::findTagWeights(20, 'humour');
$this->beginContent('@app/views/layouts/main.php');
//$this->beginContent('@app/views/layouts/main.php');
?>
<style type="text/css">
.list-group .glyphicon {
        float: right;
}
</style>
<div class="row">
    <div class="col-md-9 col-sm-8">
        <?php 
echo $content;
?>