繁体   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