我正在尝试将以下固定装置添加到我的数据库中:
$pageContent1 = new pageContent();
$pageContent1->addPageSector($this->getReference('ps1'));
$pageContent1->addPageSector($this->getReference('ps2'));
$pageContent1->setPageTypes($this->getReference('pt2'));
*$pageContent1->setPageParent(10);*
$pageContent1->setPageName('Paragraphs');
$pageContent1->setRichText('<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>');
$manager->persist($pageContent1);
由星号包围的行是导致问题的行,它应该以一对一的关系引用页面父页面。
但我收到以下错误:
[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to acme\StyleGuideBundle\Entity
\pageContent::setPageParent() must be an instance of acme\StyleGuideBund
le\Entity\pageParent, integer given, called in /Volumes/Projects/Style Guid
e/site/acmeGuidelines/src/acme/StyleGuideBundle/DataFixtures/ORM/Page
sContentFixtures.php on line 21 and defined in /Volumes/Projects/Style Guid
e/site/acmeGuidelines/src/acme/StyleGuideBundle/Entity/pageContent.ph
p line 300
错误引用的函数在此设置器上:
/**
* Set pageParent
*
* @param \acme\StyleGuideBundle\Entity\pageParent $pageParent The parent page of this page
*
* @return pageContent
*/
public function setPageParent(\acme\StyleGuideBundle\Entity\pageParent $pageParent = null)
{
$this->pageParent = $pageParent;
return $this;
}
这是使用教义从该实体自动生成的:generate:entities:
/**
* @ORM\OneToOne(targetEntity="pageContent")
* @ORM\JoinColumn(name="pageParent", referencedColumnName="id")
*/
private $pageParent;
上面引用的“targetEntity”是容器类的名称。我不确定这是否正确,但我不知道还应该设置什么。