我如何自动填充包含实体选项的表单?我正在尝试更新详细信息表单,当调用时已包含该用户信息。
我正在使用Symphony 2.1。
表单如下所示:
$builder
//->add('createdate')
//->add('modifydate')
->add('schoolname')
->add('schoolprofile')
->add('streetaddress')
->add('streetaddressext')
->add('country', 'entity', array(
'class' => 'IFS\Account\RegisterSchoolBundle\Entity\Country',
'property' => 'countryname',
))
->add('schoolprogramid', 'entity', array(
'class' => 'IFS\Account\RegisterSchoolBundle\Entity\Schoolprogram',
'property' => 'displayname',
))
->add('schoolsizegroupid', 'entity', array(
'class' => 'IFS\Account\RegisterSchoolBundle\Entity\Schoolsizegroup',
'property' => 'displayname',
))
->add('state', 'entity', array(
'class' => 'IFS\Account\RegisterSchoolBundle\Entity\State',
'property' => 'statename',
))
->add('city', 'entity', array(
'class' => 'IFS\Account\RegisterSchoolBundle\Entity\City',
'property' => 'cityname',
))
;
}
答案 0 :(得分:0)
您可以在实体级别设置默认值,例如:
class MyObject {
__construct() {
$this->setValue('myDefaultValue');
//...
}
//...
}
此外,您的问题似乎与此问题重复:How to set default value for form field in Symfony2?