首页 > 解决方案 > Sonata admin sortabe 列表,字段为空白

问题描述

我试图在我的奏鸣曲管理包中的一张表上制作一个简单的可排序系统,我已按照本教程进行操作(https://symfony.com/doc/master/bundles/SonataAdminBundle/cookbook/recipe_sortable_listing.html#the-recipe ) 但我没有能力做到这一点。

我已经仔细地执行了每个步骤,但是在我的管理表上我只能看到一个空白的操作字段,其中没有箭头。

我已经搜索并搜索了文章,但没有任何成功,我觉得我非常接近弄清楚。

这是我的 src/Entity/Podcast.php 文件

/**
* @Gedmo\SortablePosition
*@ORM\Column(name="position", type="integer")
*/
private $position;

//getters and setters 

public function setPosition($position)
{
  $this->position = $position;

  return $this;
}

public function getPosition()
{
  return $this->position;
}

据我所知,我的实体文件很好

我的 services.yaml 文件

  //Gedmo
  gedmo.listener.sortable:
    class: Gedmo\Sortable\SortableListener
    tags:
      - { name: doctrine.event_subscriber, connection: default }
    calls:
      - [ setAnnotationReader, [ "@annotation_reader" ] ]

//podcast admin
admin.podcast:
  class: App\Admin\PodcastAdmin
  tags:
    - name: sonata.admin
      manager_type: orm
      label: 'Programa'
      show_mosaic_button: true
  arguments:
    - ~
    - App\Entity\Podcast
    - 'PixSortableBehaviorBundle:SortableAdmin'
  calls:
     - [ setPositionService, ['@pix_sortable_behavior.position']]

我的 stof_doctrine_extension.yaml 文件

stof_doctrine_extensions:
default_locale: en_US
orm:
  default:
    sortable: true

最后但并非最不重要的是,我的 PodcastAdmin.php 文件

protected function configureRoutes(RouteCollection $collection)
{
  $collection->add('move', $this->getRouterIdParameter().'/move/{position}');
}

protected function configureListFields(ListMapper $listMapper) {
    $listMapper
    ->add('id')
    ->addIdentifier('title')
    ->add('description')
    ->add('author.name')
    ->add('_action', null, [
      'actions' => [
        'move' => [
          'template' => '@App/Admin/_sort.html.twig',
        ],
      ],
    ]);
}

因为现在我收到以下错误在第 17 行的@SonataAdmin/CRUD/list__action.html.twig 中没有命名空间“App”的注册路径。

如果我将模板值切换为@PixSortableBehavior/Default/_sort.html.twig,我可以看到页面但操作字段全为空白,没有箭头

标签: symfony4sonata-adminsonata

解决方案


您可以在 twig.yml 或任何类似的配置文件中注册 App 命名空间,它对我有帮助但不是最佳的。

应用程序/配置/config.yml

枝条:
    # ...
    路径:
        “%kernel.root_dir%/path/to/templates”:应用

推荐阅读