2013-10-14 4 views
1

주간 데이터를 채울 수있는 양식 모음이있는 양식을 작성하려고합니다. 나는 몇 가지 통계와 함께 일주일 동안 인 법인이Symfony 2.3.6 중첩 된 양식

/** 
* @ORM\Column(type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
protected $week_id; 

/** 
* @ORM\Column(type="string") 
*/ 
protected $area_worked; 

/** 
* @ORM\OneToMany(targetEntity="User") 
*/ 
protected $approved_by; 

/** 
* @ORM\OneToMany(targetEntity="DailyStats") 
*/ 
protected $daily_stats; 

그럼 내가 매일 통계 기관이 : 나는 출력이로 할 수있는 양식을 원하는 이들 모두 그런

/** 
* @ORM\Column(type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
protected $day_id; 

/** 
* @ORM\ManyToOne(targetEntity="WeeklyStats") 
*/ 
protected $weekly_stat_id; 

/** 
* @ORM\Column(type="float") 
*/ 
protected $hours_worked; 

/** 
* @ORM\Column(type="integer") 
*/ 
protected $day_of_week; 

을 테이블 보여주는 전체 주 :

//weekly stats form 

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder->add('dailyReports', 'collection',array(
      'type'=>new DailyStatsForm(), 
      'options' => array(
       'required' => false 
      ), 
      'allow_add' => true, 
     )); 
} 
01 : 그러나 내가 형태로이 둘 때

  Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday 
Hours |  |   |   |   |  |   | 

빈 필드 집합이있는 양식이 생성됩니다. 자바 스크립트를 사용하여 필드를 추가 할 수 있지만 가능한 경우 주간 통계의 다른 필드와 함께이 양식을 유지하는 데 항상 7 일을 생성 할 수 있는지 알고 싶습니다.

모든 제안은 크게 감사하겠습니다. 당신이 다음 symfony2 당신이 원하는 그 일곱 개 입력을 렌더링하여 주 기관에 일곱 DailyStats 엔티티를 추가하는 경우

답변

4

예는, 난 그냥 필요 않았다 http://symfony.com/doc/current/cookbook/form/form_collections.html

class TaskController extends Controller 
{ 
     public function newAction(Request $request) 
     { 
      $task = new Task(); 

      // dummy code - this is here just so that the Task has some tags 
      // otherwise, this isn't an interesting example 
      $tag1 = new Tag(); 
      $tag1->name = 'tag1'; 
      $task->getTags()->add($tag1); // any new related entity you add represents a new embeded form 
      $tag2 = new Tag(); 
      $tag2->name = 'tag2'; 
      $task->getTags()->add($tag2); 
      // end dummy code 

      $form = $this->createForm(new TaskType(), $task); 

      $form->handleRequest($request); 

      if ($form->isValid()) { 
       // ... maybe do some form processing, like saving the Task and Tag objects 
      } 

      return $this->render('AcmeTaskBundle:Task:new.html.twig', array(
       'form' => $form->createView(), 
      )); 
    } 
} 
+0

감사를 확인하시기 바랍니다, 문서를 볼 수 있습니다 양식보기를 렌더링하기 전에이를 작성하십시오. 그런 다음 추가 만 허용하지 않습니다. – Chausser