在 symfony2 奏鸣曲管理包中设置默认值 [英] setting default value in symfony2 sonata admin bundle

查看:39
本文介绍了在 symfony2 奏鸣曲管理包中设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Sonata 管理包中设置默认值configureFormFields 方法中缺少数据选项

how can i set default value in sonata admin bundle the data option is missing in configureFormFields method

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('name', null, array('required' => true, 'data' => "my default value"))
    ;
}

如何使用数据属性设置字段内的默认值???

how can use data attribute to set default value inside field ???

推荐答案

我想您现在可能已经解决了这个问题,但是作为对其他人的参考,您可以覆盖 getNewInstance() 方法并将默认值设置为对象:

I presume you've probably already solved this by now, but as a reference to anyone else you can override the getNewInstance() method and set the default value on the object:

public function getNewInstance()
{
    $instance = parent::getNewInstance();
    $instance->setName('my default value');

    return $instance;
}

这篇关于在 symfony2 奏鸣曲管理包中设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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