Yii model to array?

前端 未结 14 1969
南笙
南笙 2020-12-08 19:32

How can I convert the result of Trips::model()->findAll() to an array?

14条回答
  •  旧巷少年郎
    2020-12-08 20:03

    Easy and simple way: I use listData() method to make array to dropdown menus, and I think this will help you.. check this example:

    code:

    findAll();
    
         // format models resulting using listData     
         $tripsArray = CHtml::listData($models, 'id', 'name');    
    
         print_r($tripsArray);
    ?>
    

    output:

    array(
     '1'=>'trip1',
     '2'=>'trip2',
     '3'=>'trip3',
    )
    

提交回复
热议问题