Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

yii2 limitda xatolik bo'lyapti

+2 ovoz
48 marta ko‘rilgan
so‘radi 11 dekabr, 17 Farhodjon (1,192 bal)

Assalomu alaykum. Menda yii2 da paginationda va limit bilan muammo bo'lyapti. Asosan limit bilan.

$products = Product::find()
    ->joinWith('categories')
    ->joinWith('review')
    ->joinWith('vendor')
    ->joinWith('productProperties')
    ->filterWhere(['in', 'product_category_property_id', $filter])
    ->andFilterWhere(['product_category_link.category_id' => $category])
    ->andFilterWhere(['between', 'price', $cost_from, $cost_to])
    ->andFilterWhere(['hit' => $on_top])
    ->andFilterWhere(['in', 'brand_id', $get_brands]);
$count = clone $products;

$pagination = new Pagination([
    'defaultPageSize' => 12,
    'totalCount' => $count->count(),
]);

$products = $products->orderBy(['created_at' => SORT_DESC])
    ->offset($pagination->offset)
    ->limit($pagination->limit)
    ->all();
Muammo shundaki limitsiz products ni chiqarsam hammasi joyida chiqyapti lekin limit bersam 2 dona chiqyapti va paginatsiyalar ko'payib ketyapti. Buni pagination ishlatmasdan sinab ham ko'rdim, unda ham limit bilan muammo bo'lyapti

1 ta javob

+1 ovoz
javob berdi 12 dekabr, 17 Farhodjon (1,192 bal)

Javobini o'zim topdim. ActiveRecord join bilan ishlaganda query takrorlanishi mumkin ekan shuning uchun:

$products = Product::find()->distinct()
    ->joinWith('categories')
    ->joinWith('review')
    ->joinWith('vendor')
    ->joinWith('productProperties')
    ->andFilterWhere(['product_category_link.category_id' => $category])
    ->andFilterWhere(['hit' => 1]);

$count = clone $products;

$pagination = new Pagination([
    'totalCount' => $count->count(),
    'defaultPageSize' => 12,
]);

$products = $products->orderBy(['created_at' => SORT_DESC])
    ->offset($pagination->offset)
    ->limit($pagination->limit)
    ->all();

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...