douyaju4749 2014-08-30 12:02
浏览 23

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

I got a weird result using the Sonata Admin -- list view. Here is the snapshot.

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');
    }
} 

Entity\Department.php

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

The thing is, I did not integrate SonataUserBundle with this project as I find it inappropriate to the spec. Any ideas why am I getting an empty list view? For some reason, the configureListFilter is not called.

  • 写回答

1条回答 默认 最新

  • dongtaogou6226 2014-08-30 14:31
    关注

    Shame on me! the issue is with the function name

    configureListFilter
    

    It should be

    configureListField
    

    waaah!.. took me long to realize that typo crap.. Thanks @AldeeMativo for the help

    评论

报告相同问题?