0

I need to have pagination integrated in my Backend. I am using sonataAdminBundle. There is this Sonata\AdminBundle\Admin\Admin class which has a property called $maxPerPage = 25;

So how do i override this class so that all my other admin classes can have pagination without repeating code.

Thanks!

VishwaKumar
  • 3,433
  • 8
  • 44
  • 72

1 Answers1

2

Use Dependency Injection. In services.xml file you can add any methods that must be called when your admin service is created.

File: ../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>
pulzarraider
  • 2,297
  • 19
  • 26