0

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

那么我如何覆盖这个类,以便我所有的其他管理类可以在不重复代码的情况下进行分页。

谢谢!

4

1 回答 1

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>
于 2012-04-15T11:38:46.793 回答