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

前端 未结 5 935
孤城傲影
孤城傲影 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:03

    with Sonata 3.** in somwhere in Admin***.php script for listing all fields:

        protected function configureListFields(ListMapper $listMapper)
        {
            $listMapper
    //...
                ->addIdentifier('getCommentsCount', IntegerType::class, [ 'label' => '#Comments'])
            ;
        } 
    

    Where in Entity i written something like this:

        public function getCommentsCount()
        {
            return $this->comments->count();
        }
    

    that works for me )

提交回复
热议问题