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

前端 未结 9 2642
北荒
北荒 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:22

    How about:

    Yii::app()->db->createCommand()
        ->setFetchMode(PDO::FETCH_COLUMN,0)
        ->select("mycolumn")
        ->from(MyModel::model()->tableSchema->name)
        ->queryAll();
    

    The result would be:

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

提交回复
热议问题