Example #1
0
 /**
  * app\modules\home\models\Post
  * @return array
  */
 public function getPosts()
 {
     //return $this->hasMany(Post::className(), ['user_id' => 'id'])->orderBy('id DESC');
     $query = Post::find()->where(['user_id' => $this->id])->orderBy('id desc');
     $countQuery = clone $query;
     $pages = new \yii\data\Pagination(['totalCount' => $countQuery->count()]);
     $pages->defaultPageSize = 14;
     $posts = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['posts' => $posts, 'pages' => $pages];
 }