How to extend Sonata \ DoctrineORMAdminBundle \ Model \ ModelManager

I want some changes in ModelMangaer then I extended ModelManager but didn't work. I do not know why?

Anyone tell me why it doesn't work?

File where I expand Sonata \ DoctrineORMAdminBundle \ Model \ ModelManager->

<?php

use Sonata\DoctrineORMAdminBundle\Model\ModelManager;


class ModelManager extends ModelManager
{

/**
 * {@inheritdoc}
 */
public function getSortParameters(FieldDescriptionInterface $fieldDescription,            DatagridInterface $datagrid)
{
    $values = $datagrid->getValues();
    $values = $_GET['filter'];

    if ($fieldDescription->getName() == $values['_sort_by']) {

        if ($values['_sort_order'] == 'ASC') {
            $values['_sort_order'] = 'DESC';
        } else {
            $values['_sort_order'] = 'ASC';
        }
    } else {
        $values['_sort_order'] = 'ASC';
        $values['_sort_by']    = $fieldDescription->getName();
    }
    return array('filter' => $values);
}

      

+3


source to share


3 answers


You have a very big problem here:

class ModelManager extends ModelManager

      



You are trying to extend the class from yourself. It is not right! You must declare your base class with a Fully Qualified Name or use an operator use

. Also you forgot to put the namespace declaration. Something like this will work:

namespace Acme\Bundle\DemoBundle\Model;

use Sonata\DoctrineORMAdminBundle\Model\ModelManager as BaseClass;

class ModelManager extends BaseClass

      

+1


source


You forgot the namespace

namespace Acme\MyDoctrineORMAdminBundle\Model\ModelManager;

      



You need to use overlay overlay .

// src/Acme/MyDoctrineORMAdminBundle/MyDoctrineORMAdminBundle.php

namespace Acme\MyDoctrineORMAdminBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class MyDoctrineORMAdminBundle extends Bundle
{
    public function getParent()
    {
        return 'DoctrineORMAdminBundle';
    }
}

      

0


source


You need to change the service to be introduced, see

Administrator Documentation - Help - Advanced (Wizard) - 26.1. Service configuration

# app/config/config.yml
admins:
sonata_admin:
    sonata.order.admin.order:   # id of the admin service this setting is for
        model_manager:          # dependency name, from the table above
            sonata.order.admin.order.manager  # customised service id

      

For a separate model manager in the admin class see this answer: SonataDoctrineORM - model expands

0


source







All Articles