簡體   English   中英

如何修復Symfony2 SonataAdminBundle undefined index _per_page?

[英]How to fix Symfony2 SonataAdminBundle undefined index _per_page ?

我剛剛將symfony2.1.6升級到Symfony2.1.7並遇到了這個問題。 請告訴我,我可以提供更多詳細信息。 它在2.1.6中很好,但似乎在2.1.7中不起作用。

當我嘗試訪問Customer.php實體(客戶列表)時出現此錯誤

Notice: Undefined index: _per_page in /var/www/playground/vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Admin/Admin.php line 720

datagridValues在基本Sonata \\ AdminBundle \\ Admin \\ Admin類的$ datagridValues上初始化。 我看到這個問題的原因是人們通過分配一個完整的數組來更新代碼中的$ this-> datagridValues。 我們通過在數組中分配單個值而不是覆蓋整個數組來解決該問題。

感謝prodigitalson的評論,我通過傳遞參數解決了你的問題。

現在我的CustomerAdmin.php擴展了AbstractAdmin類,它覆蓋了Admin這個AbstractAdmin包含公共代碼,所有其他Admin類擴展了這個Abstract類。

<?php

namespace xxxx\AdminBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Doctrine\ORM\EntityManager;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;

abstract class AbstractAdmin extends Admin
{
    /** @var int */
    protected $maxPerPage = 10;
    //other attributes

    public function __construct($code, $class, $baseControllerName)
    {
        parent::__construct($code, $class, $baseControllerName);
        $this->fields = $this->sortFields($fields);

        // custome arguments
        if (!$this->hasRequest()) {
            $this->datagridValues = array(
              ***'_per_page' => $this->maxPerPage*** //passing ***_per_page*** argument
        );
    }
}


<?php

namespace xxxx\AdminBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Route\RouteCollection;

class CustomerAdmin extends AbstractAdmin
{
   //code here
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM