gpt4 book ai didi

doctrine-orm - 嵌入表单集合错误 : Could not determine access type for property

转载 作者:行者123 更新时间:2023-12-03 12:58:26 26 4
gpt4 key购买 nike

我正在尝试嵌入 Tag 的集合表格至Service表格,根据 this tutorial . TagService实体具有多对多关系。

表单正在正确呈现。但是当我提交表格时,我得到

Could not determine access type for property "tagList"



错误。我不明白为什么新 Tag对象未添加到 Service通过调用 addTag() 来上课方法。

服务类型
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class, array(
'label' => 'Title'
))
;

$builder->add('tagList', CollectionType::class, array(
'entry_type' => TagType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false
)));
}

服务等级
{
....
/**
* @ORM\ManyToMany(targetEntity="Tag", mappedBy="serviceList",cascade={"persist"})
*/
private $tagList;

/**
* @return ArrayCollection
*/
public function getTagList()
{
return $this->tagList;
}

/**
* @param Tag $tag
* @return Service
*/
public function addTag(Tag $tag)
{
if ($this->tagList->contains($tag) == false) {
$this->tagList->add($tag);
$tag->addService($this);
}
}

/**
* @param Tag $tag
* @return Service
*/
public function removeTag(Tag $tag)
{
if ($this->tagList->contains($tag)) {
$this->tagList->removeElement($tag);
$tag->removeService($this);
}
return $this;
}
}

标记类
 {
/**
* @ORM\ManyToMany(targetEntity="Service", inversedBy="tagList")
* @ORM\JoinTable(name="tags_services")
*/
private $serviceList;
/**
* @param Service $service
* @return Tag
*/
public function addService(Service $service)
{
if ($this->serviceList->contains($service) == false) {
$this->serviceList->add($service);
$service->addTag($this);
}
return $this;
}

/**
* @param Service $service
* @return Tag
*/
public function removeService(Service $service)
{
if ($this->serviceList->contains($service)) {
$this->serviceList->removeElement($service);
$service->removeTag($this);
}
return $this;
}
}

服务 Controller
  public function newAction(Request $request)
{
$service = new Service();
$form = $this->createForm('AppBundle\Form\ServiceType', $service);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$em = $this->getDoctrine()->getManager();
$em->persist($service);
$em->flush();

return $this->redirectToRoute('service_show', array('id' => $service->getId()));
}

return $this->render('AppBundle:Service:new.html.twig', array(
'service' => $service,
'form' => $form->createView(),
));
}

最佳答案

你能尝试从这个 URL 实现代码吗?

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#owning-and-inverse-side-on-a-manytomany-association

首先,请尝试更改映射/反面,并删除 $service->addTag($this);来自 Tag::addService方法。

关于doctrine-orm - 嵌入表单集合错误 : Could not determine access type for property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42246686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com