SonataAdmin:替换面包屑中的ID [英] SonataAdmin: replace ID in breadcrumbs

查看:56
本文介绍了SonataAdmin:替换面包屑中的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用其他文本替换SonataAdmin面包屑中的对象ID?

How can I replace Object's ID in SonataAdmin breadcrumbs by some other text?

如果我在文档中设置了 __ toString(),它将仅适用于编辑。当我尝试创建新记录时,在上一个面包屑中出现了 MyDocument:0000000000e09f5c000000006a48ef49 这样的东西。

If I set __toString() in my document, it works only for editing. When I attempt to create new record, there is something like MyDocument:0000000000e09f5c000000006a48ef49 in the last breadcumb.

I' m寻找一种方法,如果 Document :: toString()返回null,则允许我将一些文本设置为最后一个面包屑。

I'm searching for a method which allows me to set some text as the last breadcump if Document::toString() returns null.

推荐答案

此行为直接在实体中实现:

This behaviour is implemented directly in the entity:

public function __toString()
{
    return $this->getFoo() ? : '-';
}

捆绑软件正在使用此方法的变体,包括 return(字符串)$ this-> getFoo(); $ this-> getFoo()吗? : n / a; 等。

Bundles are using variants of this, including return (string)$this->getFoo(); or $this->getFoo() ? : 'n/a'; etc.

相关问题:用于Symfony2中SonataAdminBundle列表的toString方法

这篇关于SonataAdmin:替换面包屑中的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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