Yii2 Pagination and communication hasMany
There's a sample of the species.
$category = Category::find() ->where( 'slug = :slug', [ ':slug' => $slug ] ) ->with('items') ->one();
How is it right to organize a breakdown by page in this case without the use of dataProvider?
irl last edited by
If I understood you correctly, it must be like,
$query = Category::find() ->where( 'slug = :slug', [ ':slug' => $slug ] ) ->with('items');
$countQuery = clone $query;
$pages = new Pagination([
'totalCount' => $countQuery->count(),
'defaultPageSize' => 15,
$categories = $query->offset($pages->offset)
Well, there are categories and pages in mind, like Pagination's hands to work in a manuale on the website, like, examples.
update2: for certainty, renamed the outcome in categories, i.e., in view, foreach ($categories as $category) and within each foreach($category-graditems as $item)
Alternatively, when category one has to be visited by a range on its subjects: in that case, I suggest that the objects themselves be ploughed with a sample of the right category through the join:
$items = Item::find()->joinWith('category')->where('category.slug' => $slug)->all();
Next with the panic, it's the same as in the first option, and it's going to be the same way around the $items as $item. You can point out in the request if you have to pull something through the item-article-state... to avoid lazy underloads.