Reputation: 141
$Property = Property::find()->limit(1)->orderBy(['id' => SORT_DESC]);
I use this query with GridView but show all record
When I use this query
$Property = Property::find()->limit(1)->orderBy(['id' => SORT_DESC])->all();
show error The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
Upvotes: 0
Views: 791
Reputation: 3103
Read the documentatio here: http://www.yiiframework.com/doc-2.0/guide-output-data-providers.html#active-data-provider
Any existing limit and offset clauses will be overwritten by the pagination request from end users (through the pagination configuration).
Maybe try something like this:
$dataProvider = new ActiveDataProvider([
'query' => $Property ,
'pagination'=>[
'limit'=>1
]
]);
Read also detailed about pagination: http://www.yiiframework.com/doc-2.0/guide-output-pagination.html
And if you only want to display 1 row from a table, maybe you should check DetailView instead of GridView.
Upvotes: 1