1
如何将条件添加到我的Articles模型中,以使slug(来自类别模型)等于$ slug?Yii2模型搜索查询
这是GII生成的功能:
public function getCategory()
{
return $this->hasOne(Categories::className(), ['id' => 'category_id']);
}
这里是我的代码:
public function specificItems($slug)
{
$query = Articles::find()->with('category');
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(),'pageSize' => 12]);
$articles = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return ['articles' => $articles,'pages' => $pages];
}