0

//--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 实体。

4

1 回答 1

0

你有定义__constructorTimeSheetDaily吗?你有这样的事情吗?

public function __construct(){
//....

$this->dailyTimeSheet = new ArrayCollection();

//....
};

正确初始化此集合以便Symfony能够将数据插入其中很重要....

于 2012-03-14T13:28:46.603 回答