public function run() { parent::run(); // TODO: Change the autogenerated stub $categoriesData = PostCategory::findOne($this->category_id)->leaves()->all(); $categories = array(); $categories[] = $this->category_id; if ($categoriesData) { foreach ($categoriesData as $category) { $categories[] = $category->id; } } $offset = Post::find()->where(['in', 'category_id', $categories])->andWhere(['>', 'id', $this->node_id])->andFilterWhere(['status' => 10])->orderBy(['id' => SORT_DESC])->count(); $nodes = Post::find()->where(['in', 'category_id', $categories])->andFilterWhere(['status' => 10])->orderBy(['id' => SORT_DESC])->limit(4)->offset($offset)->all(); return $this->render('RelatedPostWidget', ['nodes' => $nodes]); }
/** * Finds the PostCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PostCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PostCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }