douguyi3903 2018-01-20 13:20
浏览 73
已采纳

Symfony 3表单:如何为textarea小部件设置默认值

I want to set the value on a textarea widget. How i can set default value for textarea in Symfony 3 for TextType(input type="text") i can use value parameter but for textarea i can not!!!how i can set default value for textarea.

this is my buildForm

    public function buildForm(FormBuilderInterface $builder, array $options)
    { 
        $builder
        ->add('linkdin', TextType::class, array('attr' => array('placeholder' => 
'linkdin','class' => 'form-control width100','value' => 
MainPageType::$content1[0]['linkdin'])))

        ->add('addres', CKEditorType::class, array('attr' => array('required' =>
 'false','name'=>'editor1' ,'id' => 'editor1','class' => 'ckeditor','empty_data'
 => MainPageType::$content1[0]['addres'])))
        .
    .
  • 写回答

3条回答 默认 最新

  • dtnrsmi824877 2018-01-20 13:26
    关注

    Assuming you are using Symfony 3.4, there's quite a good documentation for that.

    Long story short, you should use data:

    $builder->add('token', TextareaType::class, array(
        'data' => 'abcdef',
    ));
    

    As the docs say:

    The data option always overrides the value taken from the domain data (object) when rendering. This means the object value is also overriden when the form edits an already persisted object, causing it to lose its persisted value when the form is submitted.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 maixpy训练模型,模型训练好了以后,开发板通电会报错,不知道是什么问题
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容