1

我刚刚将我的 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
4

2 回答 2

2

The datagridValues are initialized on the $datagridValues of the base Sonata\AdminBundle\Admin\Admin class. The reason i saw this problem was when people where updating $this->datagridValues in their code by assigning a full array. We fixed the issue by assigning single values in the array instead of overwriting the full array.

于 2013-03-07T12:29:06.197 回答
1

感谢 prodigitalson 的评论,我通过传递参数解决了您建议的问题。

现在我的 CustomerAdmin.php 扩展了覆盖 Admin 的 AbstractAdmin 类。这个 AbstractAdmin 包含公共代码,所有其他 Admin 类都扩展了这个抽象类。

<?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
}
于 2013-02-20T05:29:47.227 回答