2012-04-06 3 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> 
관련 문제