如何扩展Sonata \ DoctrineORMAdminBundle \ Model \ ModelManager

时间:2013-01-25 05:52:06

标签: symfony extends symfony-sonata sonata-admin

我想在ModelMangaer中进行一些更改,然后我扩展了ModelManager,但它无法正常工作。我不知道为什么?

任何人都告诉我它为什么不起作用?

扩展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 个答案:

答案 0 :(得分:1)

这里有一个很大的问题:

class ModelManager extends ModelManager

你试图从自我扩展课程。这是不对的!您需要使用完全限定名称声明基类或使用use语句。你也忘记了命名空间声明。这样的事情会起作用:

namespace Acme\Bundle\DemoBundle\Model;

use Sonata\DoctrineORMAdminBundle\Model\ModelManager as BaseClass;

class ModelManager extends BaseClass

答案 1 :(得分:0)

您忘记了命名空间

namespace Acme\MyDoctrineORMAdminBundle\Model\ModelManager;

您需要使用bundle inheritance

// src/Acme/MyDoctrineORMAdminBundle/MyDoctrineORMAdminBundle.php

namespace Acme\MyDoctrineORMAdminBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

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

答案 2 :(得分:0)

您必须修改要注入的服务,请参阅:

Admin's documentation - Reference - Advanced (master) - 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

对于管理类的单个模型管理员,请参阅以下答案: SonataDoctrineORM - Model extends