当前位置: 首页>>代码示例>>PHP>>正文


PHP Comment::tableName方法代码示例

本文整理汇总了PHP中common\models\Comment::tableName方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::tableName方法的具体用法?PHP Comment::tableName怎么用?PHP Comment::tableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Comment的用法示例。


在下文中一共展示了Comment::tableName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $commentTable = Comment::tableName();
     $user = Yii::$app->getModule("user")->model("User");
     // set up query with relation to `user.username`
     $userTable = $user::tableName();
     $query->joinWith(['user' => function ($query) use($userTable) {
         $query->from(['user' => $userTable]);
     }]);
     $profileTable = \common\modules\user\models\Profile::tableName();
     $query->joinWith(['profile' => function ($query) use($profileTable) {
         $query->from(['profile' => $profileTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // enable sorting for the related columns
     $addSortAttributes = ["user.username", 'profile.full_name'];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $createdTime = strtotime($this->created_at);
     $startDay = date("Y-m-d 00:00:00", $createdTime);
     $endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
     if ($this->created_at) {
         $query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
     }
     $query->andFilterWhere(["{$commentTable}.id" => $this->id, "{$commentTable}.user_id" => $this->user_id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'profile.full_name', $this->getAttribute('profile.full_name')]);
     return $dataProvider;
 }
开发者ID:alexsynytskiy,项目名称:Dynamomania,代码行数:40,代码来源:CommentSearch.php

示例2: up

 public function up()
 {
     $comments = new \yii\db\Query();
     $comments = $comments->from(\Yii::$app->params['oldDb'] . '.joom_jcomments');
     $commentsCount = $comments->count();
     echo "    > migrating comments... Almost have {$commentsCount} comments...\r\n";
     echo "    > prepare comments...\r\n";
     $i = 0;
     $prepared = [];
     foreach ($comments->each() as $comment) {
         $i++;
         echo "    > comment {$i} from {$commentsCount}... \r\n";
         $commentModel = new Comment(['newsID' => $comment['object_id'], 'author' => $comment['name'], 'email' => $comment['email'], 'text' => $comment['comment'], 'date' => strtotime($comment['date']), 'isGood' => $comment['isgood'], 'isBad' => $comment['ispoor'], 'published' => $comment['published'], 'deleted' => $comment['deleted'], 'id' => $comment['id']]);
         $commentModel->setIp($comment['ip']);
         if (!empty($commentModel->ip) && mb_strlen($commentModel->author, 'utf8') < 64 && $commentModel->date > 0 && $commentModel->date < time() + 86400) {
             $prepared[] = $commentModel->attributes;
         }
         if (count($prepared) >= 100 || $commentsCount - $i == 0) {
             $this->batchInsert(Comment::tableName(), array_keys($prepared[0]), $prepared);
             $prepared = [];
         }
     }
 }
开发者ID:BoBRoID,项目名称:new.k-z,代码行数:23,代码来源:m160707_051700_migrate_comments.php

示例3: getComments

 /**
  * 关联关系,获取评论信息,按时间倒序排列
  * @return ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comment::className(), ['post_id' => 'id'])->orderBy(Comment::tableName() . '.created_at DESC');
 }
开发者ID:abwxwx,项目名称:yiistudy,代码行数:8,代码来源:Post.php

示例4: getCommentsCount

 /** @return integer */
 public function getCommentsCount()
 {
     return (new Query())->from(Comment::tableName())->andWhere(['model_name' => static::formName(), 'model_id' => $this->id, 'published' => 1])->andWhere('depth > 0')->count();
 }
开发者ID:tolik505,项目名称:bl,代码行数:5,代码来源:Article.php


注:本文中的common\models\Comment::tableName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。