我已阅读并尝试了本节文档中描述的所有内容,但无法正常工作。这是实体的构造函数:
public function __construct()
{
$this->targets = new ArrayCollection();
$this->targetBrand = new ArrayCollection();
}
我试图绕过使用__construct: false
但得到这个错误:
[Symfony\Component\Yaml\Exception\ParseException] 无法在第 11 行解析(靠近“名称:”)。
这是灯具的样子:
\PDI\PDOneBundle\Entity\Brand:
# 3 Brand per Company
brand{1..3}:
__construct: false
name: <name()>
generic_name: <name()>
logo_url: <imageUrl(128,128)>
description: <paragraph()>
isi_required: <boolean(35)>
isi_text: <realText()>
isi_pdf_url: <url()>
pi_required: <boolean(35)>
pi_text: <realText()>
pi_pdf_url: <url()>
inactive: <boolean(35)>
company: @company*
createdAt: <dateTimeThisYear()>
updatedAt: <dateTimeThisYear()>
如果我没有设置__construct
,那么错误会变成另一个:
[Symfony\Component\Debug\Exception\ContextErrorException] 可捕获的致命错误:传递给 Doctrine\Common\Collections\ArrayCollection::__construct() 的参数 1 必须是数组类型,给定对象,在 /var/www/html/ 中调用reptooln_admin/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php 在第 555 行并定义
怎么了?我应该如何设置夹具?
编辑:
我找到了这个,但是我如何在我试图设置的夹具上使用这种方法,有没有人能给我一些建议?
编辑1:
我有点困惑,因为Brand
被映射到TargetBrand
实体并被实体TargetBrand
反转Brand
,请参见下面的实体:
class Brand
{
// other class properties
/**
* @ORM\OneToMany(targetEntity="TargetBrand" , mappedBy="brand")
*/
protected $targetBrand;
protected $targets;
public function __construct()
{
$this->targets = new ArrayCollection();
$this->targetBrand = new ArrayCollection();
}
// other class methods
public function getTargets()
{
$targets = new ArrayCollection();
foreach ($this->targetBrand as $target) {
$targets[] = $target->getTarget();
}
return $targets;
}
public function setTargets($targets)
{
foreach ($targets as $target) {
$targetBrand = new TargetBrand();
$targetBrand->setBrand($this);
$targetBrand->setTarget($target);
$this->addTargetBrand($targetBrand);
}
}
public function addTargetBrand($targetBrand)
{
$this->targetBrand[] = $targetBrand;
}
public function removeTargetBrand($targetBrand)
{
return $this->targetBrand->removeElement($targetBrand);
}
}
class TargetBrand
{
/**
* @var int
*
* @ORM\Column(type="integer")
*/
protected $priority;
/**
* @var Target
*
* @ORM\ManyToOne(targetEntity="Target", inversedBy="targetBrand")
* @ORM\JoinColumn(name="targets_id", referencedColumnName="id")
* */
protected $target;
/**
* @var Brand
*
* @ORM\ManyToOne(targetEntity="Brand", inversedBy="targetBrand")
* @ORM\JoinColumn(name="brands_id", referencedColumnName="id")
* */
protected $brand;
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
public function getPriority()
{
return $this->priority;
}
public function setTarget(Target $targets = null)
{
$this->target = $targets;
return $this;
}
public function getTarget()
{
return $this->target;
}
public function setBrand(Brand $brand)
{
$this->brand = $brand;
return $this;
}
public function getBrand()
{
return $this->brand;
}
}
如果我使用如下集合运行固定装置:
这是我之前提到的一组:
$set->addFile(__DIR__.'/Territory.yml', 'yaml');
$set->addFile(__DIR__.'/Representative.yml', 'yaml');
$set->addFile(__DIR__.'/TargetBrand.yml', 'yaml');
$set->addFile(__DIR__.'/Target.yml', 'yaml');
$set->addFile(__DIR__.'/Brand.yml', 'yaml');
$set->addFile(__DIR__.'/Company.yml', 'yaml');
$set->addFile(__DIR__.'/Media.yml', 'yaml');
$set->addFile(__DIR__.'/Message.yml', 'yaml');
$set->addFile(__DIR__.'/Email.yml', 'yaml');
设置Brand
和TargetBrand
装置如下:
我收到了这个错误:
[Symfony\Component\Debug\Exception\ContextErrorException] 可捕获的致命错误:传递给 PDI\PDOneBundle\Entity\TargetBrand::setTarget() 的参数 1 必须是 PDI\PDOneBundle\Entity\Target 的实例,PDI\PDOneBundle\ 的实例Entity\TargetBrand 给定,在第 506 行的 /var/www/html/reptooln_admin/vendor/nelmio/alice/src/Nelmio/Alice/Loader/Base.php 中调用并定义
\PDI\PDOneBundle\Entity\Brand:
# 3 Brand per Company
brand{1..3}:
name: <name()>
generic_name: <name()>
logo_url: <imageUrl(128,128)>
description: <paragraph()>
isi_required: <boolean(35)>
isi_text: <realText()>
isi_pdf_url: <url()>
pi_required: <boolean(35)>
pi_text: <realText()>
pi_pdf_url: <url()>
inactive: <boolean(35)>
company: @company*
createdAt: <dateTimeThisYear()>
updatedAt: <dateTimeThisYear()>
targetBrand: @targetBrand*
\PDI\PDOneBundle\Entity\TargetBrand:
# 10000 TargetBrand
targetBrand{1..1000}:
priority: <randomDigitNotNull()>
target: @target*
brand: @brand*
在这种情况下加载固定装置的正确顺序是什么?
注意: $targets
不再需要,所以不要照顾那个