Yii model to array?

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

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

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 20:21

    $cats = Category::model()->findAll();
    $count_cats = count($cats);
    if($count_cats > 0){
        $arr_category = array();
        foreach($cats as $cat)
            array_push($arr_category,$cat->attributes);
    }
    print_r($arr_category);
    

    -> result

    Array(
    [0] => Array
        (
            [cat_id] => 2
            [title] => Đương đại
            [title_full] => Đương đại
            [desc] => 
            [alias] => duong-dai
            [p_id] => 0
            [type] => 1
            [status] => 1
            [sort_order] => 2
            [selected] => 0
        )
    [1] => Array
        (
            [cat_id] => 164
            [title] => Nhiệt đới
            [title_full] => Nhiệt đới
            [desc] => 
            [alias] => nhiet-doi
            [p_id] => 0
            [type] => 1
            [status] => 1
            [sort_order] => 0
            [selected] => 0
        )
    [...])
    

提交回复
热议问题