空索纳塔管理实体列表视图

时间:2014-08-30 12:02:01

标签: php symfony sonata-admin

使用Sonata Admin - list视图我得到了一个奇怪的结果。这是快照。

http://i.stack.imgur.com/AGmVI.png


config.yml:

    # ...

sonata_admin:
    title: Administration
    title_logo: extras/fi.gif

sonata_block:
    default_contexts: [cms]
    blocks:
        # Enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts:   [admin]

services.yml:

# ...

services:
    sonata.department.admin:
        class: %sonata.department.admin.class%
        tags:
            - { name: sonata.admin, manager_type: orm }

DepartmentAdmin.php

<?php

namespace Abc\Bundles\HelloBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;

use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

class DepartmentAdmin extends Admin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('Department')
                ->add('name')
            ->end();
    }

    protected function configureDatagridFilter(DatagridMapper $datagridMapper)
    {
        $datagridMapper->add('name');
    }

    protected function configureListFilter(ListMapper $listMapper)
    {
        $listMapper->addIdentifier('name');
    }
} 

实体\ Department.php

//...
public function __toString()
{
    $name = $this->getName();
    return empty($name) ? 'Add Department' : $name;
}

问题是,我没有将SonataUserBundle与此项目集成,因为我发现它不适合规范。任何想法为什么我得到一个空列表视图?出于某种原因,不会调用configureListFilter。

1 个答案:

答案 0 :(得分:0)

对我感到羞耻!问题在于函数名称

configureListFilter

应该是

configureListField

waaah!..花了我很长时间才意识到错字废话..感谢@AldeeMativo的帮助