I'm trying to display database for each user in descending date order using data provider this works for Yii 1 at controller :
$DataProvider = new CActiveDataProvider('ModelName', array(
'criteria' => array(
'condition' => 'user_id=' . Yii::app()->user->id,
'order' => 'submitted_dt DESC',
),
'pagination' => array(
'pageSize' => 20,
),
));
i try this in Yii 2 :
$DataProvider = new ActiveDataProvider([
'query' => ModelName::find(),
'criteria' => [
'condition' => 'user_id=' . Yii::$app->user->identity->id,
'order' => 'submitted_dt DESC',
],
'pagination' => [
'pageSize' => 20,
],
]);
// get posts in the current page
$Model= $DataProvider->getModels();
Error i get is unknown property: yii\data\ActiveDataProvider::criteria
.So what is the way to set this condition and order ?
All suggestions are welcomed
The
Yii2
's right way would be:So, you don't need
criteria
inYii2
as this is not exist anymore.