简体   繁体   中英

Symfony2: How do i integrate pagination in sonataAdminBundle?

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!

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM