如何使用Find()的where()添加orderBy()?

时间:2020-01-02 07:08:35

标签: php yii2 yii2-advanced-app yii2-model

如何添加带where条件的orderBy()?

$floor_data = Floors::find()->where(['building_id' => $id])->orderBy->(['floor_no' => SORT_DESC])->all();

这给了我一个语法错误,说

语法错误,意外的'(',期望的标识符(T_STRING)或变量(T_VARIABLE)或'{'或'$'

1 个答案:

答案 0 :(得分:0)

多余的->导致了错误:

$floor_data = Floors::find()
    ->where(['building_id' => $id])
    //   Remove ↓↓   
    // ->orderBy->(['floor_no' => SORT_DESC])
    ->orderBy(['floor_no' => SORT_DESC])
    ->all();
相关问题