symfony doctrine admin generator -> custom listing

强颜欢笑 提交于 2019-12-11 10:32:26

问题


I haven't found a way yet to customize what items are shown in the "list" view. To be a little bit more specific : by default all the records in a database table are selected and displayed, I want to be able to tweak a little the database select in order to select only a subset of items from the table.


回答1:


config:
  list:
    table_method: getForAdminList

Then, in a related model table class you can define your conditions to filter records:

  public function getForAdminList()
  {        
    $q = $this->createQuery('a')
      ->where('a.id > ?', 100);
    return $q;
  }

Notice that you have to return the query, not a collection of records.




回答2:


Typically you wouldn't modify the DB call, but would instead change what is shown by editing the generator.yml file.

The part you should be interested in is

config:
  list:
    display: [fields, to, display]



回答3:


In /backend/modules/*module_name*/actions/action.class.php you can override the default admin methods of that module (like in frontend). If you want to filter all querys you can override the getFilters() method and add the default param like:

class firmaActions extends autoFirmaActions
{
    protected function getFilters(){
        $filters = parent::getFilters();
        $filters['level_id'] = '3';
        return $filters;
    }
}

If you want to take a look of autoModuleActions you can find it in cache/backend/modules/autoModule/actions



来源:https://stackoverflow.com/questions/5181198/symfony-doctrine-admin-generator-custom-listing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!