public function run() { $post = Post::find(); //选择栏目 if (!empty($this->short_code)) { $post = $post->select(Post::tableName() . '.*')->joinWith(['column' => function ($query) { $query->where([Column::tableName() . '.short_code' => $this->short_code]); }]); } //选择类型 if (!empty($this->type)) { if ($this->type == static::TYPE_N) { //自动取新 $post = $post->orderBy(Post::tableName() . '.created_at DESC'); } elseif ($this->type == static::TYPE_V) { //自动取查看最多 $post = $post->orderBy(Post::tableName() . '.hits DESC'); } else { //后台指定 $post = $post->andFilterWhere(['like', Post::tableName() . '.flag', $this->type]); } } //限制数量 $models = $post->active()->limit($this->num)->all(); // fb($models); return $this->render('side-post-top', ['title' => $this->title, 'length' => $this->length, 'models' => $models]); }