如何处理 SonataAdminBundle 列表视图中的每个实体? [英] How to process each entity in SonataAdminBundle list view?

查看:20
本文介绍了如何处理 SonataAdminBundle 列表视图中的每个实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一些代码应用于管理员列表视图中显示的每个实体?

How to apply some code to each entity being displayed in Admin's list view?

例如,如果我有一个 TagManager 并且需要为每个显示的实体加载标签,我该怎么做?是否有一种方法可以在实体的 Admin 中进行覆盖,或者我可以绑定到某个列表表单事件吗?我找不到这样做的地方.

For example, if I have a TagManager and need to load tags for each entity being displayed, how do I do that? Is there a method to override in entity's Admin or can I bind to some list form event? I could not find a place to do that.

我不想绑定到实体的 onLoad 事件.

I don't wan't to bind to entity's onLoad event.

推荐答案

在您的 entityAdminController 中:

In your entityAdminController :

public function listAction()
{
    if (false === $this->admin->isGranted('LIST')) {
        throw new AccessDeniedException();
    }

    $datagrid = $this->admin->getDatagrid();
    $formView = $datagrid->getForm()->createView();

    foreach($datagrid->getResults() as $object)
    {
        //do what you want with $object
    }

    // set the theme for the current Admin Form
    $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());

    return $this->render($this->admin->getTemplate('list'), array(
        'action'   => 'list',
        'form'     => $formView,
        'datagrid' => $datagrid
    ));
}

这篇关于如何处理 SonataAdminBundle 列表视图中的每个实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆