0
創建窗體如何創建帶有2個實體 形式我有兩個實體:2個實體的Symfony 2
實體/ Cliente.php
class Cliente
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="idcliente", type="integer")
*/
private $idcliente;
/**
* @var string
*
* @ORM\Column(name="nombre", type="string", length=100)
*/
private $nombre;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set idcliente
*
* @param integer $idcliente
*
* @return Cliente
*/
public function setIdcliente($idcliente)
{
$this->idcliente = $idcliente;
return $this;
}
/**
* Get idcliente
*
* @return int
*/
public function getIdcliente()
{
return $this->idcliente;
}
/**
* Set nombre
*
* @param string $nombre
*
* @return Cliente
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
}
實體/ Contacto.php
class Contacto
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="idcliente", type="integer")
*/
private $idcliente;
/**
* @var string
*
* @ORM\Column(name="nombre", type="string", length=50)
*/
private $nombre;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set idcliente
*
* @param integer $idcliente
*
* @return Contacto
*/
public function setIdcliente($idcliente)
{
$this->idcliente = $idcliente;
return $this;
}
/**
* Get idcliente
*
* @return int
*/
public function getIdcliente()
{
return $this->idcliente;
}
/**
* Set nombre
*
* @param string $nombre
*
* @return Contacto
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
}
我想創建一個表單來輸入以下數據:
nombre(nombre在Cliente實體)
NOMBRE(NOMBRE在CONTACTO實體)
idcliente(idcliente在CONTACTO實體)(相同的存儲的值,所述客戶端實體)
是否'$ idcliente'參考'Cliente'?如果是這樣,你需要這樣開始思考對象,而不是數據庫ID。所以'Contacto'有一個'Cliente',不只是一個「id」。你的例子有點不清楚你想要做什麼 - 也許圖表會有一些幫助? – iLikeBreakfast
@iLikeBreakfast if的任何解決方案?謝謝! –