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];
}