Using column value as array index in doctrine

后端 未结 3 1077
北海茫月
北海茫月 2020-12-09 04:21

I am using doctrine 2.1 in order to create a model for settings table:

id |  arg  |  value  |  category
1  |  name |  foo    |  general_settings         


        
3条回答
  •  攒了一身酷
    2020-12-09 04:47

    Doctrine IndexBy function is used, to display column value as array index

    $this
    // database table alias
    ->createQueryBuilder( 'app_settings' )
    // first parameter should be alias and second parameter will be column name, which you want to show as array index
    ->indexBy('app_settings','app_settings.name')
    // get query
    ->getQuery()
    // get doctrine result in array format
    ->getArrayResult();
    

    The result of mentioned query will be in this format: Result of mentioned query

提交回复
热议问题