简体   繁体   中英

symfony2 - default value for “entity” field?

i am creating a form field ,this is correct in my project .

enter code here
role:
    type: entity
    attributs:
        class: 'SystemUserBundle:Group'
        property: name   
        expanded: false
        multiple: true

how add default value to this handle?

You have to make your data having a default value:

// User::getRole() = function { return new Role('DEFAULT'); }
$object = new User;
$form->setData($object);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM