Mam problem z dodaniem sub kategorii w aplikacji Symfony 3.4.6
Przy próbie stworzenia kategorii dostaję bład:
Could not determine access type for property "parent" in class "xxx\NewsBundle\Entity\Category".
<?php
namespace xxx\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="xxx\NewsBundle\Repository\CategoryRepository")
* @ORM\Table(name="news_categories")
*/
class Category extends AbstractTaxonomy {
/**
* @ORM\OneToMany(
* targetEntity = "Post",
* mappedBy = "category"
* )
*/
protected $posts;
/**
* @ORM\ManyToMany(targetEntity="category", mappedBy="parent")
*/
private $children;
/**
*
* @ORM\ManyToMany(targetEntity="category", inversedBy="children")
* @ORM\JoinTable(name="subCategory",
* joinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="parent_id", referencedColumnName="id")}
* )
*/
private $parent;
/**
* Constructor
*
* ArrayCollection
*/
public function __construct()
{
$this->children = new ArrayCollection();
$this->parent = new ArrayCollection();
}
/**
* Add child
*
* @param \xxx\NewsBundle\Entity\category $child
*
* @return Category
*/
public function addChild(\xxx\NewsBundle\Entity\category $child)
{
$this->children[] = $child;
return $this;
}
/**
* Remove child
*
* @param \xxx\NewsBundle\Entity\category $child
*/
public function removeChild(\xxx\NewsBundle\Entity\category $child)
{
$this->children->removeElement($child);
}
/**
* Get children
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* Add parent
*
* @param \xxx\NewsBundle\Entity\category $parent
*
* @return Category
*/
public function addParent(\xxx\NewsBundle\Entity\category $parent)
{
$this->parent[] = $parent;
return $this;
}
/**
* Remove parent
*
* @param \xxx\NewsBundle\Entity\category $parent
*/
public function removeParent(\xxx\NewsBundle\Entity\category $parent)
{
$this->parent->removeElement($parent);
}
/**
* Get parent
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getParent()
{
return $this->parent;
}
}
<?php
namespace xxx\AdminBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class CategoryType extends TaxonomyType {
public function getName() {
return 'taxonomy';
}
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', TextType::class, array(
'label' => 'Tytuł'
))
->add('slug', TextType::class, array(
'label' => 'Alias'
))
->add('parent', EntityType::class, array(
'choice_label' => 'name',
'label' => false,
'class' => \xxx\NewsBundle\Entity\Category::class,
'attr' => array(
'class' => 'selectpicker fullwidth-select',
'data-placeholder' => 'Wybierz kategorię'
)
))
->add('save', SubmitType::class, array(
'label' => 'Zapisz'
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'xxx\NewsBundle\Entity\AbstractTaxonomy'
));
}
}
Struktura Bazy danych jest stworzona