2012-04-06 7 views
0

バックエンドにページネーションを統合する必要があります。私はsonataAdminBundleを使用しています。 このSonata \ AdminBundle \ Admin \ Adminクラスには、$ maxPerPage = 25というプロパティがあります。Symfony2:どのように私はsonataAdminBundleでページネーションを統合しますか?

このクラスをオーバーライドすると、他のすべての管理クラスがコードを繰り返さずにページネーションを持つことができます。

ありがとうございます!

答えて

2

依存性注入を使用します。 services.xmlファイルには、管理サービスの作成時に呼び出されるメソッドを追加できます。

ファイル:../YourAdminBundle/Resources/config/services.xml:

<?xml version="1.0" ?> 
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> 

    <parameters> 
     <!-- You define the maxpage only once --> 
     <parameter key="admin_max_per_page_number">10</parameter> 
    </parameters> 
    <services> 

     <service id="xyz_admin" class="Abc\Bundle\YourAdminBundle\Admin\XyzAdmin"> 
      <tag name="sonata.admin" manager_type="orm" group="xyz_group" label="Xyz"/> 
      <argument /> 
      <argument>Abc\Bundle\YourAdminBundle\Entity\Xyz</argument> 
      <argument>SonataAdminBundle:CRUD</argument> 

      <call method="setMaxPerPage"> 
       <argument>%admin_max_per_page_number%</argument> 
      </call> 
     </service> 

     <!-- ... another admin services... --> 
    </services> 
</container> 
関連する問題