The line $groupement[] = null === $secteurs ? null : $secteurs->getSecteurid();
in the Eleveurtype.php is not working Please i need Some help
The work i wanted to do is to select one Secteur and then i want to get all groupements belong to the Secteur
This is The EleveurType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('secteurid',EntityType::class, [
'label'=>'Nom du secteur :',
'class' => Secteurs::class,
'choice_label' => 'secteurfr',
'attr'=>[
'class'=>'form-control',
]
])
;
$formModifier = function (FormInterface $form, Secteurs $secteurs = null) {
//$secteurs = null === $secteurs ? [] : $secteurs->getSecteurid();
$groupement[] = null === $secteurs ? null : $secteurs->getSecteurid();
$form->add('groupementid', EntityType::class, [
'class' => Groupements::class,
'placeholder' => '',
'choices' => $groupement,
'attr'=>[
'class'=>'form-control',
]
]);
};
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($formModifier) {
// this would be your entity, i.e. SportMeetup
$data = $event->getData();
$formModifier($event->getForm(), $data->getSecteurid());
}
);
$builder->get('secteurid')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($formModifier) {
// It's important here to fetch $event->getForm()->getData(), as
// $event->getData() will get you the client data (that is, the ID)
$secteur = $event->getForm()->getData();
// since we've added the listener to the child, we'll have to pass on
// the parent to the callback functions!
$formModifier($event->getForm()->getParent(), $secteur);
}
);
}
This is The _form.html.twig Eleveur
{{ form_start(form, {'attr': {'id': 'newform', 'nam': nam } }) }}
{{ form_widget(form) }}
<button type="button" class="{{ classBtnAddEdit|default('btn btnAED btn-success waves-effect waves-light m-1') }} " id="btnAddEdit"><i class="fa fa-check-square-o"></i> Enregistrer</button>
{{ form_end(form) }}
<script>
var $secteur = $('#eleveurs_secteurid');
// When sport gets selected ...
$secteur.change(function() {
// ... retrieve the corresponding form.
var $form = $(this).closest('form');
// Simulate form data, but only include the selected sport value.
var data = {};
data[$secteur.attr('name')] = $secteur.val();
// Submit data via AJAX to the form's action path.
$.ajax({
url : $form.attr('nam'), //= $form.attr('action'),
type: $form.attr('method'),
data : data,
success: function(html) {
// Replace current position field ...
$('#eleveurs_groupementid').replaceWith(
// ... with the returned one from the AJAX response.
$(html).find('#eleveurs_groupementid')
);
// Position field now displays the appropriate positions.
}
});
});
</script>
** this is the Eleveur Class Eleveur **
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Eleveurs
*
* @ORM\Table(name="eleveurs", indexes={@ORM\Index(name="fk_relationship_47", columns={"groupementid"}), @ORM\Index(name="fk_relationship_53", columns={"douarid"}), @ORM\Index(name="fk_relationship_16", columns={"secteurid"}), @ORM\Index(name="fk_relationship_49", columns={"villeid"})})
* @ORM\Entity
*/
class Eleveurs
{
/**
* @var int
*
* @ORM\Column(name="eleveurid", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $eleveurid;
/**
* @var string|null
*
* @ORM\Column(name="codeeleveur", type="text", length=65535, nullable=true)
*/
private $codeeleveur;
/**
* @var string|null
*
* @ORM\Column(name="numcin", type="text", length=65535, nullable=true)
*/
private $numcin;
/**
* @var \DateTime|null
*
* @ORM\Column(name="datecin", type="date", nullable=true)
*/
private $datecin;
/**
* @var \DateTime|null
*
* @ORM\Column(name="validitecin", type="date", nullable=true)
*/
private $validitecin;
/**
* @var string|null
*
* @ORM\Column(name="nomfr", type="text", length=65535, nullable=true)
*/
private $nomfr;
/**
* @var string|null
*
* @ORM\Column(name="prenomfr", type="text", length=65535, nullable=true)
*/
private $prenomfr;
/**
* @var string|null
*
* @ORM\Column(name="nomar", type="text", length=65535, nullable=true)
*/
private $nomar;
/**
* @var string|null
*
* @ORM\Column(name="prenomar", type="text", length=65535, nullable=true)
*/
private $prenomar;
/**
* @var \DateTime|null
*
* @ORM\Column(name="dateadhesion", type="date", nullable=true)
*/
private $dateadhesion;
/**
* @var string|null
*
* @ORM\Column(name="adressefr", type="text", length=65535, nullable=true)
*/
private $adressefr;
/**
* @var string|null
*
* @ORM\Column(name="adressear", type="text", length=65535, nullable=true)
*/
private $adressear;
/**
* @var int|null
*
* @ORM\Column(name="effectifovin", type="integer", nullable=true)
*/
private $effectifovin;
/**
* @var int|null
*
* @ORM\Column(name="effectifcaprin", type="integer", nullable=true)
*/
private $effectifcaprin;
/**
* @var \Secteurs
*
* @ORM\ManyToOne(targetEntity="Secteurs")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="secteurid", referencedColumnName="secteurid")
* })
*/
private $secteurid;
/**
* @var \Groupements
*
* @ORM\ManyToOne(targetEntity="Groupements")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="groupementid", referencedColumnName="groupementid")
* })
*/
private $groupementid;
/**
* @var \Villes
*
* @ORM\ManyToOne(targetEntity="Villes")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="villeid", referencedColumnName="villeid")
* })
*/
private $villeid;
/**
* @var \Douars
*
* @ORM\ManyToOne(targetEntity="Douars")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="douarid", referencedColumnName="douarid")
* })
*/
private $douarid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Conseilgroupement", mappedBy="eleveurid")
*/
private $conseilgroupementid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Droitfonctionement", inversedBy="eleveurid")
* @ORM\JoinTable(name="relationship_32",
* joinColumns={
* @ORM\JoinColumn(name="eleveurid", referencedColumnName="eleveurid")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="droitfonctionementid", referencedColumnName="droitfonctionementid")
* }
* )
*/
private $droitfonctionementid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Conseilanoc", mappedBy="eleveurid")
*/
private $conseilanocid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Superviseurs", mappedBy="eleveurid")
*/
private $histosuperviseurid;
/**
* Constructor
*/
public function __construct()
{
$this->conseilgroupementid = new \Doctrine\Common\Collections\ArrayCollection();
$this->droitfonctionementid = new \Doctrine\Common\Collections\ArrayCollection();
$this->conseilanocid = new \Doctrine\Common\Collections\ArrayCollection();
$this->histosuperviseurid = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getEleveurid(): ?int
{
return $this->eleveurid;
}
public function getCodeeleveur(): ?string
{
return $this->codeeleveur;
}
public function setCodeeleveur(?string $codeeleveur): self
{
$this->codeeleveur = $codeeleveur;
return $this;
}
public function getNumcin(): ?string
{
return $this->numcin;
}
public function setNumcin(?string $numcin): self
{
$this->numcin = $numcin;
return $this;
}
public function getDatecin(): ?\DateTimeInterface
{
return $this->datecin;
}
public function setDatecin(?\DateTimeInterface $datecin): self
{
$this->datecin = $datecin;
return $this;
}
public function getValiditecin(): ?\DateTimeInterface
{
return $this->validitecin;
}
public function setValiditecin(?\DateTimeInterface $validitecin): self
{
$this->validitecin = $validitecin;
return $this;
}
public function getNomfr(): ?string
{
return $this->nomfr;
}
public function setNomfr(?string $nomfr): self
{
$this->nomfr = $nomfr;
return $this;
}
public function getPrenomfr(): ?string
{
return $this->prenomfr;
}
public function setPrenomfr(?string $prenomfr): self
{
$this->prenomfr = $prenomfr;
return $this;
}
public function getNomar(): ?string
{
return $this->nomar;
}
public function setNomar(?string $nomar): self
{
$this->nomar = $nomar;
return $this;
}
public function getPrenomar(): ?string
{
return $this->prenomar;
}
public function setPrenomar(?string $prenomar): self
{
$this->prenomar = $prenomar;
return $this;
}
public function getDateadhesion(): ?\DateTimeInterface
{
return $this->dateadhesion;
}
public function setDateadhesion(?\DateTimeInterface $dateadhesion): self
{
$this->dateadhesion = $dateadhesion;
return $this;
}
public function getAdressefr(): ?string
{
return $this->adressefr;
}
public function setAdressefr(?string $adressefr): self
{
$this->adressefr = $adressefr;
return $this;
}
public function getAdressear(): ?string
{
return $this->adressear;
}
public function setAdressear(?string $adressear): self
{
$this->adressear = $adressear;
return $this;
}
public function getEffectifovin(): ?int
{
return $this->effectifovin;
}
public function setEffectifovin(?int $effectifovin): self
{
$this->effectifovin = $effectifovin;
return $this;
}
public function getEffectifcaprin(): ?int
{
return $this->effectifcaprin;
}
public function setEffectifcaprin(?int $effectifcaprin): self
{
$this->effectifcaprin = $effectifcaprin;
return $this;
}
public function getSecteurid(): ?Secteurs
{
return $this->secteurid;
}
public function setSecteurid(?Secteurs $secteurid): self
{
$this->secteurid = $secteurid;
return $this;
}
public function getGroupementid(): ?Groupements
{
return $this->groupementid;
}
public function setGroupementid(?Groupements $groupementid): self
{
$this->groupementid = $groupementid;
return $this;
}
public function getVilleid(): ?Villes
{
return $this->villeid;
}
public function setVilleid(?Villes $villeid): self
{
$this->villeid = $villeid;
return $this;
}
public function getDouarid(): ?Douars
{
return $this->douarid;
}
public function setDouarid(?Douars $douarid): self
{
$this->douarid = $douarid;
return $this;
}
/**
* @return Collection|Conseilgroupement[]
*/
public function getConseilgroupementid(): Collection
{
return $this->conseilgroupementid;
}
public function addConseilgroupementid(Conseilgroupement $conseilgroupementid): self
{
if (!$this->conseilgroupementid->contains($conseilgroupementid)) {
$this->conseilgroupementid[] = $conseilgroupementid;
$conseilgroupementid->addEleveurid($this);
}
return $this;
}
public function removeConseilgroupementid(Conseilgroupement $conseilgroupementid): self
{
if ($this->conseilgroupementid->contains($conseilgroupementid)) {
$this->conseilgroupementid->removeElement($conseilgroupementid);
$conseilgroupementid->removeEleveurid($this);
<
** This is the Secteur class **
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Secteurs
*
* @ORM\Table(name="secteurs")
* @ORM\Entity
*/
class Secteurs
{
/**
* @var int
*
* @ORM\Column(name="secteurid", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $secteurid;
/**
* @var string|null
*
* @ORM\Column(name="secteurfr", type="text", length=65535, nullable=true)
*/
private $secteurfr;
/**
* @var string|null
*
* @ORM\Column(name="secteurar", type="text", length=65535, nullable=true)
*/
private $secteurar;
/**
* @var string|null
*
* @ORM\Column(name="codesecteur", type="text", length=65535, nullable=true)
*/
private $codesecteur;
public function getSecteurid(): ?int
{
return $this->secteurid;
}
public function getSecteurfr(): ?string
{
return $this->secteurfr;
}
public function setSecteurfr(?string $secteurfr): self
{
$this->secteurfr = ucfirst($secteurfr);
return $this;
}
public function getSecteurar(): ?string
{
return $this->secteurar;
}
public function setSecteurar(?string $secteurar): self
{
$this->secteurar = $secteurar;
return $this;
}
public function getCodesecteur(): ?string
{
return $this->codesecteur;
}
public function setCodesecteur(?string $codesecteur): self
{
$this->codesecteur = strtoupper($codesecteur);
return $this;
}
}
** this is the groupement class **
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Groupements
*
* @ORM\Table(name="groupements", indexes={@ORM\Index(name="fk_relationship_54", columns={"secteurid"})})
* @ORM\Entity
*/
class Groupements
{
/**
* @var int
*
* @ORM\Column(name="groupementid", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $groupementid;
/**
* @var string|null
*
* @ORM\Column(name="groupementmereid", type="decimal", precision=8, scale=0, nullable=true)
*/
private $groupementmereid;
/**
* @var string|null
*
* @ORM\Column(name="codegroupement", type="text", length=65535, nullable=true)
*/
private $codegroupement;
/**
* @var string|null
*
* @ORM\Column(name="nomgroupementfr", type="text", length=65535, nullable=true)
*/
private $nomgroupementfr;
/**
* @var string|null
*
* @ORM\Column(name="nomgroupementar", type="text", length=65535, nullable=true)
*/
private $nomgroupementar;
/**
* @var string|null
*
* @ORM\Column(name="adressepostale", type="text", length=65535, nullable=true)
*/
private $adressepostale;
/**
* @var \DateTime|null
*
* @ORM\Column(name="datecreation", type="date", nullable=true)
*/
private $datecreation;
/**
* @var string|null
*
* @ORM\Column(name="pvcreation", type="text", length=65535, nullable=true)
*/
private $pvcreation;
/**
* @var float|null
*
* @ORM\Column(name="droitfonctionement", type="float", precision=10, scale=0, nullable=true)
*/
private $droitfonctionement;
/**
* @var float|null
*
* @ORM\Column(name="autrecotisations", type="float", precision=10, scale=0, nullable=true)
*/
private $autrecotisations;
/**
* @var string|null
*
* @ORM\Column(name="effectifovinencadre", type="decimal", precision=8, scale=0, nullable=true)
*/
private $effectifovinencadre;
/**
* @var string|null
*
* @ORM\Column(name="effectifcaprinencadre", type="decimal", precision=8, scale=0, nullable=true)
*/
private $effectifcaprinencadre;
/**
* @var string|null
*
* @ORM\Column(name="lieupvcreation", type="text", length=65535, nullable=true)
*/
private $lieupvcreation;
/**
* @var \DateTime|null
*
* @ORM\Column(name="datepvcreation", type="date", nullable=true)
*/
private $datepvcreation;
/**
* @var \Secteurs
*
* @ORM\ManyToOne(targetEntity="Secteurs")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="secteurid", referencedColumnName="secteurid")
* })
*/
private $secteurid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Droitfonctionement", inversedBy="groupementid")
* @ORM\JoinTable(name="relationship_31",
* joinColumns={
* @ORM\JoinColumn(name="groupementid", referencedColumnName="groupementid")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="droitfonctionementid", referencedColumnName="droitfonctionementid")
* }
* )
*/
private $droitfonctionementid;
/**
* Constructor
*/
public function __construct()
{
$this->droitfonctionementid = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getGroupementid(): ?int
{
return $this->groupementid;
}
public function getGroupementmereid(): ?string
{
return $this->groupementmereid;
}
public function setGroupementmereid(?string $groupementmereid): self
{
$this->groupementmereid = $groupementmereid;
return $this;
}
public function getCodegroupement(): ?string
{
return $this->codegroupement;
}
public function setCodegroupement(?string $codegroupement): self
{
$this->codegroupement = $codegroupement;
return $this;
}
public function getNomgroupementfr(): ?string
{
return $this->nomgroupementfr;
}
public function setNomgroupementfr(?string $nomgroupementfr): self
{
$this->nomgroupementfr = $nomgroupementfr;
return $this;
}
public function getNomgroupementar(): ?string
{
return $this->nomgroupementar;
}
public function setNomgroupementar(?string $nomgroupementar): self
{
$this->nomgroupementar = $nomgroupementar;
return $this;
}
public function getAdressepostale(): ?string
{
return $this->adressepostale;
}
public function setAdressepostale(?string $adressepostale): self
{
$this->adressepostale = $adressepostale;
return $this;
}
public function getDatecreation(): ?\DateTimeInterface
{
return $this->datecreation;
}
public function setDatecreation(?\DateTimeInterface $datecreation): self
{
$this->datecreation = $datecreation;
return $this;
}
public function getPvcreation(): ?string
{
return $this->pvcreation;
}
public function setPvcreation(?string $pvcreation): self
{
$this->pvcreation = $pvcreation;
return $this;
}
public function getDroitfonctionement(): ?float
{
return $this->droitfonctionement;
}
public function setDroitfonctionement(?float $droitfonctionement): self
{
$this->droitfonctionement = $droitfonctionement;
return $this;
}
public function getAutrecotisations(): ?float
{
return $this->autrecotisations;
}
public function setAutrecotisations(?float $autrecotisations): self
{
$this->autrecotisations = $autrecotisations;
return $this;
}
public function getEffectifovinencadre(): ?string
{
return $this->effectifovinencadre;
}
public function setEffectifovinencadre(?string $effectifovinencadre): self
{
$this->effectifovinencadre = $effectifovinencadre;
return $this;
}
public function getEffectifcaprinencadre(): ?string
{
return $this->effectifcaprinencadre;
}
public function setEffectifcaprinencadre(?string $effectifcaprinencadre): self
{
$this->effectifcaprinencadre = $effectifcaprinencadre;
return $this;
}
public function getLieupvcreation(): ?string
{
return $this->lieupvcreation;
}
public function setLieupvcreation(?string $lieupvcreation): self
{
$this->lieupvcreation = $lieupvcreation;
return $this;
}
public function getDatepvcreation(): ?\DateTimeInterface
{
return $this->datepvcreation;
}
public function setDatepvcreation(?\DateTimeInterface $datepvcreation): self
{
$this->datepvcreation = $datepvcreation;
return $this;
}
public function getSecteurid(): ?Secteurs
{
return $this->secteurid;
}
public function setSecteurid(?Secteurs $secteurid): self
{
$this->secteurid = $secteurid;
return $this;
}
/**
* @return Collection|Droitfonctionement[]
*/
public function getDroitfonctionementid(): Collection
{
return $this->droitfonctionementid;
}
public function addDroitfonctionementid(Droitfonctionement $droitfonctionementid): self
{
if (!$this->droitfonctionementid->contains($droitfonctionementid)) {
$this->droitfonctionementid[] = $droitfonctionementid;
}
return $this;
}
public function removeDroitfonctionementid(Droitfonctionement $droitfonctionementid): self
{
if ($this->droitfonctionementid->contains($droitfonctionementid)) {
$this->droitfonctionementid->removeElement($droitfonctionementid);
}
return $this;
}
}