//--form timesheettype---不是实体类
class TimeSheetType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
$builder->
add('dailyTimeSheet', 'collection', array('type' => new DailyType(), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true,))
->add('comment','textarea');
}
public function getName() {
return 'TimeSheetDaily';
}
}
//--- DailyType -- 该类型有实体
class DailyType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
$builder->add('project','entity',array('class'=> 'Parabola\EntityBundle\Entity\Project','property'=>'name'))
->add('projectTask', 'entity', array('class'=> 'Parabola\EntityBundle\Entity\ProjectTask','property'=>'name'))
->add('hours', 'text');
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'Parabola\EntityBundle\Entity\TimeSheetDaily');
}
public function getName() {
return 'DailySheet';
}
// - 控制器 -
$repository = $this->getDoctrine()
->getRepository('ParabolaEntityBundle:TimeSheetDaily')->findAll();
$form = $this->createForm(new \Parabola\TimeSheetBundle\Form\TimeSheetType(),$repository);
我有实体类 TimeSheetDaily。在构建 TimeSheetType 表单时,我将 TimeSheetDaily 类对象数组传递给表单类型。并且 TimeSheetType 具有 DailyType 的集合。它不是为集合字段设置值,它只是一个 TimeSheetDaily 实体。