Symfony2 Sonata Admin 仅将属性显示为现成文本 [英] Symfony2 Sonata Admin show attribute only as a readyonly text

查看:17
本文介绍了Symfony2 Sonata Admin 仅将属性显示为现成文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的实体有一些不可变的属性,需要使用 Sonata-admin 包进行管理.

I have some immutable attributes on my entity to administrate with sonata-admin bundle.

我想在实体的编辑视图中显示它们,但不想提供任何更改它的机制(例如,值不应在输入字段内)

I want to show them in the edit-view of the entity, but don't want to provide any mechanism to change it (e.g. the value shall not be inside a input field)

除了这个我什么都找不到:

I couldn't find anything but this:

$formMapper
    ->add('post', 'entity', 
        array(
            'label' => 'Some post', 
            'attr' => array(
                'readonly' => true,
                'disabled' => true
            ),
            'class' => 'Acme\DemoBundle\Entity\Post'
        )
    )
;

我用 read_onlyreadonlydisabled 等所有东西进行了尝试.看起来不错,它现在在下拉列表中(因为它是一个实体),我无法修改它.

I tried it out with read_only, readonly, disabled etc. all the stuff. It looks ok, it's now inside a dropdown (since it is an entity) and I can not modify it.

但我什至不想要那样.我真的需要它作为文本(当前的).

But I even don't want that. I really need it as text (the current one).

特别是如果你使用 DoctrineExtensions 和 softdeletable、timestampable 会很烦人,因为每次保存"也会保存表单数据.

将类型更改为文本"而不​​是实体"会将下拉列表替换为输入字段.那么,这里最好的方法是什么?

Changing the type to 'text' instead of 'entity' replaces the dropdown with a input-field.. So, what's the best approach here?

推荐答案

$formMapper
    ->add('post', 'entity', 
        array(
            'label' => 'Some post',
            'read_only' => true,
            'disabled'  => true,
            'class' => 'Acme\DemoBundle\Entity\Post'
        )
    )
;

这篇关于Symfony2 Sonata Admin 仅将属性显示为现成文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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