Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony2表格。使用2个表单字段和3个表为第4个表返回一个id';什么记录?_Symfony - Fatal编程技术网

Symfony2表格。使用2个表单字段和3个表为第4个表返回一个id';什么记录?

Symfony2表格。使用2个表单字段和3个表为第4个表返回一个id';什么记录?,symfony,Symfony,我有3个表提供地理位置数据(这篇文章简化了) 当有人去添加地址时,我希望他们选择一个国家并输入他们的邮政编码。由于世界上多个城市可能有相同的zipcode,这使我们能够找出它们在哪里。在国家/地区/城市表中。使用类似于此的查询 SELECT crc.id as crc_id FROM countries c, country_regions cr, country_region_cities crc WHERE c.id=231 and crc.postal_code

我有3个表提供地理位置数据(这篇文章简化了)

当有人去添加地址时,我希望他们选择一个国家并输入他们的邮政编码。由于世界上多个城市可能有相同的zipcode,这使我们能够找出它们在哪里。在国家/地区/城市表中。使用类似于此的查询

SELECT 
  crc.id as crc_id
FROM
  countries c,
  country_regions cr,
  country_region_cities crc
WHERE 
  c.id=231 and
  crc.postal_code='02199' and
  cr.country_id = c.id and
  cr.id = crc.country_region_id
方法是将crc.id存储在任何需要地址数据的表中,而不是存储完整地址。我不知道如何将这两个字段(country\u id和postal\u code)添加到表单中,并将country\u region\u city:id存储在需要它的表的数据库字段中


我觉得我需要创建一个AbstractType并将其链接到需要存储relationaship的表单,但是我是否需要为涉及的其他两个表创建更多AbstractType?

方法是通过一个自定义数据转换器对象,如Symfony cookbook中所述

一旦我意识到这一点,我就在几个小时内完成了任务,而且它正在愉快地工作

SELECT 
  crc.id as crc_id
FROM
  countries c,
  country_regions cr,
  country_region_cities crc
WHERE 
  c.id=231 and
  crc.postal_code='02199' and
  cr.country_id = c.id and
  cr.id = crc.country_region_id