简体   繁体   中英

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. 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.

This error comes when I try to access Customer.php Entity (customer listing)

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. 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.

Thanks prodigitalson for comment, I solved the issue as you suggested by passing the argument.

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.

<?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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM