Yii - How to get a values array from an Active Record

前端 未结 9 2562
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 13:12

Using Yii, how can I get an array from an Active Record.

Say something like this:

array(\'foo\', \'bar\', \'lala\')

From something like thi

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-15 13:27

    Use the Yii2 ArrayHelper by including to your controller this will convert a model data to an associated array

        use yii\helpers\ArrayHelper; 
    
        $post = ArrayHelper::toArray(ClientProfilesForm::findOne(['id' => 1]));
    
    //or use it directly by 
    
        $post = yii\helpers\ArrayHelper::toArray(ClientProfilesForm::findOne(['id' => 1]));
    

提交回复
热议问题