简体   繁体   English

如何修复Symfony2 SonataAdminBundle undefined index _per_page?

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

I just upgraded my symfony2.1.6 to Symfony2.1.7 and bumped in to this issue. 我刚刚将symfony2.1.6升级到Symfony2.1.7并遇到了这个问题。 Please let me know I can provide more details. 请告诉我,我可以提供更多详细信息。 It was fine with 2.1.6 but does not seem to work in 2.1.7. 它在2.1.6中很好,但似乎在2.1.7中不起作用。

This error comes when I try to access Customer.php Entity (customer listing) 当我尝试访问Customer.php实体(客户列表)时出现此错误

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

The datagridValues are initialized on the $datagridValues of the base Sonata\\AdminBundle\\Admin\\Admin class. datagridValues在基本Sonata \\ AdminBundle \\ Admin \\ Admin类的$ datagridValues上初始化。 The reason i saw this problem was when people where updating $this->datagridValues in their code by assigning a full array. 我看到这个问题的原因是人们通过分配一个完整的数组来更新代码中的$ this-> datagridValues。 We fixed the issue by assigning single values in the array instead of overwriting the full array. 我们通过在数组中分配单个值而不是覆盖整个数组来解决该问题。

Thanks prodigitalson for comment, I solved the issue as you suggested by passing the argument. 感谢prodigitalson的评论,我通过传递参数解决了你的问题。

Now my CustomerAdmin.php extends AbstractAdmin class which is overriding the Admin This AbstractAdmin contains common code and all other Admin classes extends this Abstract Class. 现在我的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