내가

2014-04-18 3 views
1

내가 내 데이터베이스를 검사 할 때 내가 어떤 행을 찾을 수 없습니다 2.4과 교리 내 데이터베이스 심포니에 데이터를 삽입 할 수 없습니다, 데이터가 나는 오류내가

입니다 잘 모릅니다 심포니 2.4 doctrine2 를 사용하여 메신저 발견

은 여기 내 locationType에

<?php 

namespace carRental\MainBundle\Form; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 
use Symfony\Component\OptionsResolver\OptionsResolverInterface; 

class LocationType extends AbstractType { 

    /** 
    * @param FormBuilderInterface $builder 
    * @param array $options 
    */ 
public function buildForm(FormBuilderInterface $builder, array $options) { 
    $builder 
      ->add('fullName', 'text', array(
       'attr' => array(
        'class' => 'form-control' 
       ) 
      )) 
      ->add('email', 'email', array(
       'attr' => array(
        'class' => 'form-control' 
     ))) 
      ->add('phone', 'number', array(
       'attr' => array(
        'class' => 'form-control' 
     ))) 
      ->add('placeLivrai', 'text', array(
       'attr' => array(
        'class' => 'form-control' 
     ))) 
      ->add('placeRecu', 'text', array(
       'attr' => array(
        'class' => 'form-control' 
     ))) 
      ->add('dateLivrai', 'date') 
      ->add('dateBack', 'date') 
      ->add('car', 'choice', array(
       'choices' => array(
        'fiatPanda' => 'fiat Panda', 
        'hyundaih1' => 'Hyundai H1', 
        'daciaLogan' => 'Dacia Logan', 
        'fiatpunto' => 'Fiat Punto', 
       ), 
       'attr' => array(
        'class' => 'form-control' 
       ) 
      )) 
      ->add('country', 'country', array(
       'attr' => array(
        'class' => 'form-control' 
     ))) 
      ->add('gPS', 'checkbox', array(
       'required' => false 
      )) 
      ->add('siegeBebe', 'checkbox', array(
       'required' => false 
      )) 
      ->add('message', 'textarea', array(
       'attr' => array(
        'class' => 'form-control' 
     ))) 
      ->getForm(); 
} 

/** 
* @param OptionsResolverInterface $resolver 
*/ 
public function setDefaultOptions(OptionsResolverInterface $resolver) { 
    $resolver->setDefaults(array(
     'data_class' => 'carRental\MainBundle\Entity\Location' 
    )); 
} 

/** 
* @return string 
*/ 
public function getName() { 
    return 'carrental_mainbundle_location'; 
} 

}

입니다 그리고 이것은 내 locationAction입니다

public function locationAction() { 
    // Reservation Form 
    $em = $this->getDoctrine()->getManager(); 
    $location = new Location(); 
    $form = $this->createForm(new LocationType(), $location); 
    $request = $this->getRequest(); 
    if ($request->isMethod('POST')) { 
     $form->handleRequest($request); 
     if ($form->isValid()) { 
      $em->persist($form->getData()); 
      $em->flush(); 
      $this->get('session')->getFlashBag()->add('Reservation', 'Votre réservation a été bien envoyé'); 
      /* return $this->redirect($this->generateUrl('home_main_homepage')); */ 
     } 
    } 
    return $this->render('carRentalMainBundle:Main:location.html.twig', array(
       'form' => $form->createView(), 
    )); 
} 
,

이것은

{% extends 'carRentalMainBundle::layout.html.twig' %} 
{% block body %} 
<div class="container"> 
{% for flashMessage in app.session.flashbag.get('Reservation') %} 
    <ul><li class="alert-success"> 
    {{flashMessage}} 
     </li></ul> 
{% endfor%} 
    <br/> 
    <div class="col-md-4"> 
     <form method="POST" action="{{path('carrental_mainbundle_location')}}" {{ form_enctype(form) }} > 

     {{form_errors(form)}} 
      <div class="form-group"> 
     {{ form_label(form.fullName,'*Nom et Prénom') }} 
     {{ form_errors(form.fullName) }} 
     {{ form_widget(form.fullName) }} 
      </div> 
      <div class="form-group"> 
      {{ form_label(form.email,'*Email :') }} 
     {{ form_errors(form.email) }} 
     {{ form_widget(form.email) }} 
      </div> 
      <div class="form-group"> 
      {{ form_label(form.phone,'*Téléphone :') }} 
     {{ form_errors(form.phone) }} 
     {{ form_widget(form.phone) }} 

      </div> 
      <div class="form-group"> 

      {{ form_label(form.placeLivrai,'*Place de livraison :') }} 
     {{ form_errors(form.placeLivrai) }} 
     {{ form_widget(form.placeLivrai) }} 
      </div> 
      <div class="form-group"> 
      {{ form_label(form.placeRecu,'*Place de récupération :') }} 
     {{ form_errors(form.placeRecu) }} 
     {{ form_widget(form.placeRecu) }} 

      </div> 
      <div class="form-group"> 

      {{ form_label(form.dateLivrai,'*Date de livraison : ') }} 
     {{ form_errors(form.dateLivrai) }} 
     {{ form_widget(form.dateLivrai) }} 
      </div> 
      <div class="form-group"> 

      {{ form_label(form.dateBack,'*Date de retour :') }} 
     {{ form_errors(form.dateBack) }} 
     {{ form_widget(form.dateBack) }} 
      </div> 
      <div class="form-group"> 

      {{ form_label(form.car,'*Voiture :') }} 
     {{ form_errors(form.car) }} 
     {{ form_widget(form.car) }} 
      </div> 
      <div class="form-group"> 

      {{ form_label(form.country,'*Pays :') }} 
     {{ form_errors(form.country) }} 
     {{ form_widget(form.country) }} 
      </div> 
      <div class="form-group"> 

      {{ form_label(form.gPS,'GPS :') }} 
     {{ form_errors(form.gPS) }} 
     {{ form_widget(form.gPS) }} 
      </div> 
      <div class="form-group"> 

      {{ form_label(form.siegeBebe,'Siége bébé :') }} 
     {{ form_errors(form.siegeBebe) }} 
     {{ form_widget(form.siegeBebe) }} 
      </div> 
      <div class="form-group"> 

      {{ form_label(form.message,'Message :') }} 
     {{ form_errors(form.message) }} 
     {{ form_widget(form.message) }} 
      </div> 
      {{form_rest(form)}} 
      <input type="submit" value="Envoyer" class="btn btn-primary "> 

     </form> 
    </div> 
</div> 
    {% endblock %} 

가 컨트롤러에 $location 객체 대신 $form->getData()을 저장하기 위해 당신의 도움

답변

0

시도 주셔서 감사합니다 내이다. 나는. 변경

$ em-> persist ($ form-> getData());

$ 보하기> 계속 ($의 위치);

carrental_mainbundle_location은 양식 작업 속성에서 올바른 경로 이름 locationAction 방법입니까?

file 필드를 사용하지 않는 것으로 보입니다. 따라서 양식 태그에 {{ form_enctype(form) }}이 정말로 필요합니까?

템플릿의 열기 및 닫기 양식 태그를 {{ form_start(form) }}{{ form_end(form) }}으로 변경하는 것이 좋습니다.