In my yii2 application list view need to show only 5 product limit. This my View page
<?= ListView::widget( [
'dataProvider' => $dataProvider,
'itemView' => '_item',
'summary' => '',
] ); ?>
and this my controller
$searchModel = new HorseAdsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
this my Model search Function
public function search($params)
{
$query = HorseAds::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'product_id' => $this->product_id,
'producttype' => $this->producttype,
'productname' => $this->productname,
]);
return $dataProvider;
}
Please help me solve this, thanks
Try somthing like this: idea is that set limit with find and set pagination to false