3
votes

Am using yii2 find() and would like to return only first five records

THIS IS what ive tried

 $items= \frontend\models\TblResearch::find()->orderBy("id")->all();

That returs all the records what am looking for is

 $items= \frontend\models\TblResearch::find()->orderBy("id")
        ->all(); //instead of all use like something to return five records

How do i go about this

I would like only to use the model approach not the sql

1
for more information and clarity you can goto stackoverflow.com/questions/32155900/use-limit-range-in-yii2 - Ankur Soni

1 Answers

4
votes

Use limit()

$items= \frontend\models\TblResearch::find()->orderBy("id")->limit(5)->all();