1
我正在構建計算機配置程序並獲得了四個實體。使用「嵌套」數組集合生成Doctrine實體
- 客戶(不相關)
- 電腦(ID,客戶,串口,日期,[成分])
- ArticleGroup(ID,姓名)
- 條(ID,名稱,價格,articleGroup,活性)
屬性的計算機實體的[成分]應包含一個這樣的數組:
$components = array(
'CPU' => array(
'name' => 'Intel Core i7',
'count' => 1,
'price' => 275),
'Mainboard' => array(
'name' => 'Gigabyte H97-D3H',
'count' => 1,
'price' => 75),
'RAM' => array(
'name' => '4GB DDRIII Kingston Value Ram',
'count' => 4,
'price' => 28),
'SSD' => array(
'name' => '512GB Samsung 850 Pro',
'count' => 1,
'price' => 400)
);
陣列鍵的價格可能不同於物品實體的價格(因爲硬件的每日價格或因爲我認爲這個客戶得到的CPU較少的錢)
現在我不知道如何的問題創建這個組件數組集合。
這是我的計算機實體:
<?php
namespace ctcrm\ConfiguratorBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Computer
*
* @ORM\Table()
* @ORM\Entity
*/
class Computer
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @Assert\NotBlank()
* @Assert\Length(
* min = 12,
* max = 12,
* minMessage = "no valid serial!",
* maxMessage = "no valid serial!"
*)
* @ORM\Column(name="serial", type="string", length=12)
*/
private $serial;
/**
* @var \DateTime
* @Assert\NotBlank()
* @ORM\Column(name="date", type="date")
*/
private $date;
/**
* @ORM\ManyToOne(targetEntity="Customer")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* @Assert\NotBlank()
**/
private $customer;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set serial
*
* @param string $serial
* @return Computer
*/
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
/**
* Get serial
*
* @return string
*/
public function getSerial()
{
return $this->serial;
}
/**
* Set date
*
* @param \DateTime $date
* @return Computer
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* @return mixed
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param mixed $customer
*/
public function setCustomer($customer)
{
$this->customer = $customer;
}
}