Symfony2:我如何在sonataAdminBundle中整合分页?

时间:2012-04-06 10:18:02

标签: symfony pagination admin symfony-sonata

我需要在我的后端集成分页。我正在使用sonataAdminBundle。 这个Sonata \ AdminBundle \ Admin \ Admin类有一个名为$ maxPerPage = 25的属性;

那么我如何覆盖这个类,以便我的所有其他管理类都可以分页而不重复代码。

谢谢!

1 个答案:

答案 0 :(得分: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>
相关问题