Yii2 - ActiveRecord to Array

后端 未结 3 1952
情歌与酒
情歌与酒 2021-01-01 11:03

Is there any way to convert ActiveRecord to an array in Yii2? I do know we can do that for ActiveQuery, for example User::find()->asArray(

3条回答
  •  醉话见心
    2021-01-01 11:37

    Try this!

    $model = Post::find($id)->limit(10)->asArray()->all();
    $model = Post::find($id)->select('id,name as full')->asArray()->one();
    $model = Post::find($id)->select('id,name as full')->asArray()->all();
    $model = Post::find()->where(['slug'=>$slug])->asArray()->one();
    

提交回复
热议问题