Symfony Select2

I am tring to use this Select2 bundle into my Symfony project.
https://github.com/tetranz/select2entity-bundle

NUCLEI ENTITY

/**
 * Nuclei
 *
 * @ORMTable(name="datinuclei")
 * @ORMEntity(repositoryClass="AppRepositoryNucleiRepository")
 */
class Nuclei
{
    /**
     * @var int
     *
     * @ORMId
     * @ORMColumn(name="id", type="integer", nullable=false)
     * @ORMGeneratedValue(strategy="NONE")
     */
    private $id;

    /**
     * @var string
     *
     * @ORMColumn(name="codicenucleo", type="string", nullable=false)
     */
    private $codicenucleo;

    /**
     * @var Tag
     *
     * @ORMOneToMany(targetEntity="Tag", mappedBy="nucleo")
     * @ORMJoinColumn(name="idnucleo", referencedColumnName="id")
     */
    private $codicitag;


    public function __construct()
    {
    $this->codicitag = new ArrayCollection();
    }

    public function __toString()
    {
    return  $this->getCodiceNucleo();
    }

    public function getId(): ?int
    {
    return $this->id;
    }

    public function getTipoNucleo(): ?int
    {
    return $this->tiponucleo;
    }

    public function getCodiceNucleo(): ?string
    {
    return $this->codicenucleo;
    }


    /**
     * @return Collection|Tag[]
     */
    public function getCodiciTag(): Collection
    {
    return $this->codicitag;
    }

    public function getStatistiche(): ?NucleiStatistiche
    {
    return $this->statistiche;
    }

}

TAG ENTITY

/**
 * Tag
 *
 * @ORMTable(name="infonuclei")
 * @ORMEntity
 */
class Tag
{
    /**
     * @var int
     *
     * @ORMId
     * @ORMColumn(name="id", type="integer", nullable=false)
     * @ORMGeneratedValue(strategy="NONE")
     */
    private $id;

    /**
     * @var string
     *
     * @ORMColumn(name="codicetag", type="string", nullable=false)
     */
    private $codicetag;

    /**
     * @var Nuclei
     *
     * @ORMManyToOne(targetEntity="Nuclei", inversedBy="codicitag")
     * @ORMJoinColumn(name="idnucleo", referencedColumnName="id")
     */
    private $nucleo;

    public function __toString()
    {
    return  $this->getCodicetag();
    }

    public function getId(): ?int
    {
    return $this->id;
    }

    public function getCodicetag(): ?string
    {
    return $this->codicetag;
    }

    public function getNucleo(): ?Nuclei
    {
    return $this->nucleo;
    }

    public function setCodicetag(string $codicetag): self
    {
    $this->codicetag = $codicetag;

    return $this;
    }

    public function setNucleo(Nuclei $nucleo): self
    {
    $this->nucleo = $nucleo;

    return $this;
    }

}

This is my form builder class implements Select2EntityType

$builder
    ->add('codicitag', Select2EntityType::class, [
    'multiple' => false,
    'remote_route' => 'tag_search_json',
    'class' => 'AppEntityTag',
    'text_property' => 'codicetag',
    'minimum_input_length' => 2,
    'page_limit' => 10,
    'allow_clear' => true,
    'delay' => 250,
    'placeholder' => 'Select a country'
    ])
    ->add('submit', SubmitType::class);

this throw an error i don’t understand why

Neither the property "codicetag" nor one of the methods "getCodicetag()", "codicetag()", "isCodicetag()", "hasCodicetag()", "__get()" exist and have public access in class "DoctrineORMPersistentCollection".

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *