엔티티 자체 아래에 uniqueConstraints
에 메시지를 첨부하려면 어떻게합니까? 아래의 두 번째 쿼리는 An exception occurred while executing....SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry...
을 생성합니다. 이 비우호적 인 메시지 대신 "나는 무엇이든 무엇이든 요청하십시오 ..."를 어떻게 인쇄 할 수 있습니까?Symfony2의 UniqueConstraint 오류 메시지 처리
SQL 2INSERT INTO cars (model, brands_id) VALUES ('bmw', '5')
주 1INSERT INTO cars (model, brands_id) VALUES ('bmw', '5')
SQL : 나는 일반적으로 심포니 문서가 좋지 발견하고 대부분의 지름길이 될 것으로 보인다. 당신은 해결책을 찾고있는 누군가가 그 답을 알고 있다면 당신이있어하지 않을 경우 당신은 ....
ENTITY
/**
* @ORM\Entity
* @ORM\Table(name="cars", uniqueConstraints={@ORM\UniqueConstraint(columns={"model", "brands_id"})})
*/
class Cars
{
CONTROLLER 행운을 경우
try
{
$submission = $form->getData();
$em = $this->getDoctrine()->getManager();
$cars = new Cars();
$cars->setModel($submission->getModel());
$cars->setBrands($submission->getBrands());
$em->persist($cars);
$em->flush();
.......
}
catch (Exception $e)
{
......
}
형식 유형
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->setAction($options['action'])
->setMethod('POST')
->add('brands', 'entity',
array(
'class' => 'CarBrandBundle:Brands',
'property' => 'name',
'multiple' => false,
'expanded' => false,
'empty_value' => '',
'query_builder' => function (EntityRepository $repo)
{
return $repo->createQueryBuilder('b')->orderBy('b.name', 'ASC');
}
))
->add('model', 'text', array('label' => 'Model'))
->add('button', 'submit', array('label' => 'Submit'))
;
}
양식 제출 후이 INSERT를 보냅니 까? – DonCallisto
예 양식 유형에서 왔습니다. – BentCoder
위에 참조로 양식 유형을 추가했습니다. – BentCoder