2012-10-17 3 views
1

도움이 필요합니다. 작성한 양식을 Symfony2에 표시하고 싶습니다. 컨트롤러 : 나는 내 데이터베이스 (모든 숫자는 한 형태)에서 92 개 번호가 렸기 때문에 내 생성 된 형태로 92 시간을 표시 할, 내가 여기 어떻게 해야할지 몰랐 내 코드입니다양식 symfony2, Symfony2에서 만든 양식 표시

class DefaultController extends Controller 
{ 
public function QuestionsAction(Request $request) 
{ 
    $questions = $this->getDoctrine()->getEntityManager() 
      ->getRepository('Tests\TestsPhpBundle\Entity\Question')  
      ->findAll(); 
    $task = new Question(); 
    $forms = $this->createForm(new QuestionType(), $task); 
    if ($request->getMethod() == 'POST') { 
    $forms->bindRequest($request);    
     if ($forms->isValid()) 
     { 
      $em = $this->getDoctrine()->getEntityManager(); 
      $em->persist($task); 
      $em->flush(); 
      }     
    } 
     { 
return $this->render('TestsTestsPhpBundle:Default:index.html.twig', array(
     'questions' => $questions, 
     'forms' => $forms->createView() 
        ));  
     } 

} 
} 

내 양식 파일 :

class QuestionType extends AbstractType 
     { 
     public function buildForm(FormBuilder $builder, array $options) 
     { 


     $builder 
      ->add('categories', null, array('required' => false,            
              ))           

      ->add('text', 'entity', array(
         'class' => 'TestsTestsPhpBundle:Question', 
         'query_builder' => function($repository) { 
    return $repository->createQueryBuilder('p')->orderBy('p.id', 'ASC'); }, 
         'property' => 'text')) 
       ; 
    } 
    public function getDefaultOptions(array $options) 
    { 
     return array(
      'data_class' => 'Tests\TestsPhpBundle\Entity\Question',); 
    } 
    public function getName() 
    { 
     return 'question'; 
    } 
    } 

내 나뭇 가지 파일 : 임베딩 컨트롤러: 나는 capter을 읽을 것을 권장합니다

{% block content %} 

    <h2>Questions</h2> 

    {% for question in questions %} 

    <dl> 
    <dt>Number</dt> 
    <dd>{{ question.number }}<dd> 

    {% for form in forms %} 

    {{ form_row(forms.categories) }} 
    {{ form_row(forms.text) }} 

    </dl> 
     {% endfor %} 
     <hr /> 
    {% endfor %} 
    {% endblock %} 

답변

1

http://symfony.com/doc/2.0/book/templating.html

<div id="sidebar"> 
    {% render "AcmeArticleBundle:Article:recentArticles" with {'max': 3} %} 
</div> 

당신은 나뭇 가지 템플릿 내에서 루프를 만들 수 있으며 (필요한 경우 매개 변수) 양식을 렌더링 할 경우 작업을 호출합니다. - 당신의 사건에 대한 질문.