Sonata Admin Bundle: show total count of collection on list view

前端 未结 5 967
孤城傲影
孤城傲影 2021-01-06 04:50

Is there any way to show total count of collection on list view? Imagine that there is a user that can have many links. How can I show total links count on list view?

5条回答
  •  粉色の甜心
    2021-01-06 05:14

    Yes you can show the total count of links for each user, i assume you have arraycollection of links defined in your user entity, define a property named as $totalLinks and in getter of that property return count of links something like below

    class User{
    
        public $totalLinks;
        public function getTotalLinks(){
            return count($this->getLinks());
        }
    }
    

    and then in your configureListFields() you can add $totalLinks property

    protected function configureListFields(ListMapper $list)
    {
        $list
        ->add('...')
        ->add('...')
        ->add('totalLinks');
    }
    

提交回复
热议问题