के लिए एक्सेस प्रकार निर्धारित नहीं कर सका this tutorial के अनुसार फ़ॉर्म में Tag
रूपों का संग्रह एम्बेड करने का प्रयास कर रहा हूं। Tag
और Service
इकाइयों में कई से अधिक संबंध हैं।प्रपत्रों का संग्रह एम्बेड करें त्रुटि:
फॉर्म सही ढंग से प्रस्तुत कर रहा है। लेकिन जब मैं फॉर्म जमा करता हूं, तो मुझे
Could not determine access type for property "tagList"
त्रुटि मिलती है। मुझे समझ में नहीं आता कि ऑब्जेक्ट Service
क्लास में addTag()
विधि को कॉल करके क्यों नहीं जोड़ा गया है।
ServiceType
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;
}
}
ServiceController
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(),
));
}
http://stackoverflow.com/questions/41213014/could-not-determine-access -type-for-property-file – craigh
यहां असफल परीक्षण है जो त्रुटि उत्पन्न करता है, शायद इसे समझने में सहायता मिलेगी: https://github.com/symfony/property-access/blob/master/Tests/PropertyAccessorCollectionTest.php#L151 – craigh
@craigh अगर मैं 'mapped => false' करता हूं, तो मैं 'टैगलिस्ट' को संपादित नहीं कर पाऊंगा, क्योंकि यह लिखेगा, लेकिन – blahblah