![](/img/trans.png)
[英]Symfony2: How do i overwrite maxPerPage property in pagination for sonataAdminBundle?
[英]Symfony2: How do i integrate pagination in sonataAdminBundle?
我需要在我的后端中集成分頁。 我正在使用 sonataAdminBundle。 這個 Sonata\AdminBundle\Admin\Admin class 有一個名為 $maxPerPage = 25 的屬性;
那么我如何覆蓋這個 class 以便我所有其他管理類都可以在不重復代碼的情況下進行分頁。
謝謝!
使用依賴注入。 在 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.