How to handle multiple fields with the same name in symfony2 - php

I have to submit a form (sell) with multiple fields, some of them are from an entity and the others are customed fields that i can duplicate (products) with JQuery.
the problem is that in the createAction i get just one of each duplicated field (the last one).
This is my form type :
$builder
->add('montant')
->add('dateDebut', 'date', array( 'input' => 'datetime','widget' => 'single_text'))
->add('dateFin', 'date', array('input' => 'datetime', 'widget' => 'single_text'))
->add('statutVente', 'choice', array('choices' => array('Oui' => 'Oui','A finaliser' => 'A finaliser', 'A encaisser' => 'A encaisser', 'Non' => 'Non' ),'choices_as_values' => true))
->add('objet', 'choice', array('choices' => array('Entrant' => 'Entrant','Prospection' => 'Prospection', 'Renouvellement ' => 'Renouvellement' ),'choices_as_values' => true))
->add('moyenPaiement', 'choice', array('choices' => array('CB' => 'CB','Chèque' => 'Chèque', 'Virement ' => 'Virement', 'Espèces' => 'Espèces', 'Paypal' => 'Paypal', 'Autre' => 'Autre' ),'choices_as_values' => true))
->add('numeroCommande')
->add('devise', 'choice', array('choices' => array('MAD' => 'MAD','EURO' => 'EURO', 'DOLLAR ' => 'DOLLAR' ),'choices_as_values' => true))
->add('nomFacturation')
->add('tva', 'choice', array('choices' => array('OUI' => 'OUI','NON' => 'NON'),'choices_as_values' => true))
->add('reduction')
->add('adresseFacturation')
->add('cpFacturation')
->add('villeFacturation')
->add('raison')
->add('produit', 'entity', array('class' => 'VENTEBundle\\Entity\\Produit', 'mapped' => false, 'attr' => array('class'=>'add_form') ))
->add('compte', 'text', array('mapped'=> false))
->add('Sujet', null, array('mapped' => false))
->add('sujetappel', null, array('mapped' => false))
->add('Note', 'textarea', array( 'attr' => array( 'placeholder'=>""),'mapped' => false))
->add('remindertime', 'datetime', array('date_widget' => 'single_text','time_widget' => 'single_text', 'format' => 'dd-MM-yyyy HH:mm','mapped' => false,
'attr' => array( 'data-provide' => 'datepicker',
'data-date-format' => 'dd-mm-yyyy' )))
->add('dateappel', 'datetime', array('date_widget' => 'single_text','time_widget' => 'single_text', 'format' => 'dd-MM-yyyy','mapped' => false,
'attr' => array( 'data-provide' => 'datepicker',
'data-date-format' => 'dd-mm-yyyy' )))
->add('quantite', 'text', array('mapped' => false))
->add('montant_total', 'text', array('mapped' => false))
->add('nbr_personne', 'text', array('mapped' => false))
->add('duree', 'text', array('mapped' => false))
->add('description', 'textarea', array('mapped' => false));
}
And this is the jquery function that duplicate the fields :
$("#add_product").on('click', function(){
var i=1;
var original = document.getElementById('form_container_child');
var clone = original.cloneNode(true); // "deep" clone
var elements = document.getElementsByTagName('div');
clone.id = "form_container_child" + ++i;
original.parentNode.append(clone);
})
This is my sell entity (vente)
<?php
namespace VENTEBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Vente
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="VENTEBundle\Entity\VenteRepository")
*/
class Vente
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var float
*
* #ORM\Column(name="montant", type="float")
*/
private $montant;
/**
* #var \DateTime
*
* #ORM\Column(name="date_debut", type="date")
*/
private $dateDebut;
/**
* #var \DateTime
*
* #ORM\Column(name="date_fin", type="date")
*/
private $dateFin;
/**
* #var \DateTime
*
* #ORM\Column(name="date_creation", type="datetime")
*/
private $dateCreation;
/**
* #var string
*
* #ORM\Column(name="statut_vente", type="string", length=100)
*/
private $statutVente;
/**
* #var string
*
* #ORM\Column(name="objet", type="string", length=100)
*/
private $objet;
/**
* #var string
*
* #ORM\Column(name="moyen_paiement", type="string", length=100)
*/
private $moyenPaiement;
/**
* #var string
*
* #ORM\Column(name="numero_commande", type="string", length=120)
*/
private $numeroCommande;
/**
* #var string
*
* #ORM\Column(name="devise", type="string", length=20)
*/
private $devise;
/**
* #var string
*
* #ORM\Column(name="nom_facturation", type="string", length=255)
*/
private $nomFacturation;
/**
* #var string
*
* #ORM\Column(name="tva", type="string", length=255)
*/
private $tva;
/**
* #var float
*
* #ORM\Column(name="reduction", type="float")
*/
private $reduction;
/**
* #var string
*
* #ORM\Column(name="adresse_facturation", type="string", length=500)
*/
private $adresseFacturation;
/**
* #var string
*
* #ORM\Column(name="cpfacturation", type="string", length=20)
*/
private $cpFacturation;
/**
* #var string
*
* #ORM\Column(name="ville_facturation", type="string", length=40)
*/
private $villeFacturation;
/**
* #ORM\ManyToOne(targetEntity="Raison", inversedBy="ventes")
* #ORM\JoinColumn(name="raison_id", referencedColumnName="id")
*/
private $raison;
/**
* #ORM\ManyToOne(targetEntity="COMPTEBundle\Entity\Compte", inversedBy="ventes")
* #ORM\JoinColumn(name="compte_id", referencedColumnName="id")
*/
private $compte;
/**
* #ORM\OneToMany(targetEntity="Venteproduit", mappedBy="vente")
*/
private $venteproduits;
/**
* #ORM\OneToMany(targetEntity="Ventedocument", mappedBy="vente")
*/
private $ventedocuments;
/**
* #ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="ventes")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* Constructor
*/
public function __construct()
{
$this->venteproduits = new \Doctrine\Common\Collections\ArrayCollection();
$this->ventedocuments = new \Doctrine\Common\Collections\ArrayCollection();
$this->dateCreation = new \Datetime();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set montant
*
* #param float $montant
* #return Vente
*/
public function setMontant($montant)
{
$this->montant = $montant;
return $this;
}
/**
* Get montant
*
* #return float
*/
public function getMontant()
{
return $this->montant;
}
/**
* Set dateDebut
*
* #param \DateTime $dateDebut
* #return Vente
*/
public function setDateDebut($dateDebut)
{
$this->dateDebut = $dateDebut;
return $this;
}
/**
* Get dateDebut
*
* #return \DateTime
*/
public function getDateDebut()
{
return $this->dateDebut;
}
/**
* Set dateFin
*
* #param \DateTime $dateFin
* #return Vente
*/
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
return $this;
}
/**
* Get dateFin
*
* #return \DateTime
*/
public function getDateFin()
{
return $this->dateFin;
}
/**
* Set dateCreation
*
* #param \DateTime $dateCreation
* #return Vente
*/
public function setDateCreation($dateCreation)
{
$this->dateCreation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* #return \DateTime
*/
public function getDateCreation()
{
return $this->dateCreation;
}
/**
* Set statutVente
*
* #param string $statutVente
* #return Vente
*/
public function setStatutVente($statutVente)
{
$this->statutVente = $statutVente;
return $this;
}
/**
* Get statutVente
*
* #return string
*/
public function getStatutVente()
{
return $this->statutVente;
}
/**
* Set objet
*
* #param string $objet
* #return Vente
*/
public function setObjet($objet)
{
$this->objet = $objet;
return $this;
}
/**
* Get objet
*
* #return string
*/
public function getObjet()
{
return $this->objet;
}
/**
* Set moyenPaiement
*
* #param string $moyenPaiement
* #return Vente
*/
public function setMoyenPaiement($moyenPaiement)
{
$this->moyenPaiement = $moyenPaiement;
return $this;
}
/**
* Get moyenPaiement
*
* #return string
*/
public function getMoyenPaiement()
{
return $this->moyenPaiement;
}
/**
* Set numeroCommande
*
* #param string $numeroCommande
* #return Vente
*/
public function setNumeroCommande($numeroCommande)
{
$this->numeroCommande = $numeroCommande;
return $this;
}
/**
* Get numeroCommande
*
* #return string
*/
public function getNumeroCommande()
{
return $this->numeroCommande;
}
/**
* Set devise
*
* #param string $devise
* #return Vente
*/
public function setDevise($devise)
{
$this->devise = $devise;
return $this;
}
/**
* Get devise
*
* #return string
*/
public function getDevise()
{
return $this->devise;
}
/**
* Set nomFacturation
*
* #param string $nomFacturation
* #return Vente
*/
public function setNomFacturation($nomFacturation)
{
$this->nomFacturation = $nomFacturation;
return $this;
}
/**
* Get nomFacturation
*
* #return string
*/
public function getNomFacturation()
{
return $this->nomFacturation;
}
/**
* Set tva
*
* #param string $tva
* #return Vente
*/
public function setTva($tva)
{
$this->tva = $tva;
return $this;
}
/**
* Get tva
*
* #return string
*/
public function getTva()
{
return $this->tva;
}
/**
* Set reduction
*
* #param float $reduction
* #return Vente
*/
public function setReduction($reduction)
{
$this->reduction = $reduction;
return $this;
}
/**
* Get reduction
*
* #return float
*/
public function getReduction()
{
return $this->reduction;
}
/**
* Set adresseFacturation
*
* #param string $adresseFacturation
* #return Vente
*/
public function setAdresseFacturation($adresseFacturation)
{
$this->adresseFacturation = $adresseFacturation;
return $this;
}
/**
* Get adresseFacturation
*
* #return string
*/
public function getAdresseFacturation()
{
return $this->adresseFacturation;
}
/**
* Set cpFacturation
*
* #param string $cpFacturation
* #return Vente
*/
public function setCpFacturation($cpFacturation)
{
$this->cpFacturation = $cpFacturation;
return $this;
}
/**
* Get cpFacturation
*
* #return string
*/
public function getCpFacturation()
{
return $this->cpFacturation;
}
/**
* Set villeFacturation
*
* #param string $villeFacturation
* #return Vente
*/
public function setVilleFacturation($villeFacturation)
{
$this->villeFacturation = $villeFacturation;
return $this;
}
/**
* Get villeFacturation
*
* #return string
*/
public function getVilleFacturation()
{
return $this->villeFacturation;
}
/**
* Set raison
*
* #param \VENTEBundle\Entity\Raison $raison
* #return Vente
*/
public function setRaison(\VENTEBundle\Entity\Raison $raison = null)
{
$this->raison = $raison;
return $this;
}
/**
* Get raison
*
* #return \VENTEBundle\Entity\Raison
*/
public function getRaison()
{
return $this->raison;
}
/**
* Set compte
*
* #param \COMPTEBundle\Entity\Compte $compte
* #return Vente
*/
public function setCompte(\COMPTEBundle\Entity\Compte $compte = null)
{
$this->compte = $compte;
return $this;
}
/**
* Get compte
*
* #return \COMPTEBundle\Entity\Compte
*/
public function getCompte()
{
return $this->compte;
}
/**
* Add venteproduits
*
* #param \VENTEBundle\Entity\Venteproduit $venteproduits
* #return Vente
*/
public function addVenteproduit(\VENTEBundle\Entity\Venteproduit $venteproduits)
{
$this->venteproduits[] = $venteproduits;
return $this;
}
/**
* Remove venteproduits
*
* #param \VENTEBundle\Entity\Venteproduit $venteproduits
*/
public function removeVenteproduit(\VENTEBundle\Entity\Venteproduit $venteproduits)
{
$this->venteproduits->removeElement($venteproduits);
}
/**
* Get venteproduits
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getVenteproduits()
{
return $this->venteproduits;
}
/**
* Add ventedocuments
*
* #param \VENTEBundle\Entity\Ventedocument $ventedocuments
* #return Vente
*/
public function addVentedocument(\VENTEBundle\Entity\Ventedocument $ventedocuments)
{
$this->ventedocuments[] = $ventedocuments;
return $this;
}
/**
* Remove ventedocuments
*
* #param \VENTEBundle\Entity\Ventedocument $ventedocuments
*/
public function removeVentedocument(\VENTEBundle\Entity\Ventedocument $ventedocuments)
{
$this->ventedocuments->removeElement($ventedocuments);
}
/**
* Get ventedocuments
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getVentedocuments()
{
return $this->ventedocuments;
}
/**
* Set user
*
* #param \UserBundle\Entity\User $user
* #return Vente
*/
public function setUser(\UserBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return \UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
}
And this is the products entity (produit)
<?php
namespace VENTEBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Venteproduit
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="VENTEBundle\Entity\VenteproduitRepository")
*/
class Venteproduit
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="quantite", type="integer")
*/
private $quantite;
/**
* #var float
*
* #ORM\Column(name="montant_total", type="float")
*/
private $montantTotal;
/**
* #var integer
*
* #ORM\Column(name="nbr_personne", type="integer")
*/
private $nbrPersonne;
/**
* #var string
*
* #ORM\Column(name="duree", type="string", length=50)
*/
private $duree;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=500)
*/
private $description;
/**
* #ORM\ManyToOne(targetEntity="Vente", inversedBy="venteproduits")
* #ORM\JoinColumn(name="vente_id", referencedColumnName="id")
*/
private $vente;
/**
* #ORM\ManyToOne(targetEntity="Produit", inversedBy="venteproduits")
* #ORM\JoinColumn(name="produit_id", referencedColumnName="id")
*/
private $produit;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set quantite
*
* #param integer $quantite
* #return Venteproduit
*/
public function setQuantite($quantite)
{
$this->quantite = $quantite;
return $this;
}
/**
* Get quantite
*
* #return integer
*/
public function getQuantite()
{
return $this->quantite;
}
/**
* Set montantTotal
*
* #param float $montantTotal
* #return Venteproduit
*/
public function setMontantTotal($montantTotal)
{
$this->montantTotal = $montantTotal;
return $this;
}
/**
* Get montantTotal
*
* #return float
*/
public function getMontantTotal()
{
return $this->montantTotal;
}
/**
* Set nbrPersonne
*
* #param integer $nbrPersonne
* #return Venteproduit
*/
public function setNbrPersonne($nbrPersonne)
{
$this->nbrPersonne = $nbrPersonne;
return $this;
}
/**
* Get nbrPersonne
*
* #return integer
*/
public function getNbrPersonne()
{
return $this->nbrPersonne;
}
/**
* Set duree
*
* #param string $duree
* #return Venteproduit
*/
public function setDuree($duree)
{
$this->duree = $duree;
return $this;
}
/**
* Get duree
*
* #return string
*/
public function getDuree()
{
return $this->duree;
}
/**
* Set description
*
* #param string $description
* #return Venteproduit
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set vente
*
* #param \VENTEBundle\Entity\Vente $vente
* #return Venteproduit
*/
public function setVente(\VENTEBundle\Entity\Vente $vente = null)
{
$this->vente = $vente;
return $this;
}
/**
* Get vente
*
* #return \VENTEBundle\Entity\Vente
*/
public function getVente()
{
return $this->vente;
}
/**
* Set produit
*
* #param \VENTEBundle\Entity\Produit $produit
* #return Venteproduit
*/
public function setProduit(\VENTEBundle\Entity\Produit $produit = null)
{
$this->produit = $produit;
return $this;
}
/**
* Get produit
*
* #return \VENTEBundle\Entity\Produit
*/
public function getProduit()
{
return $this->produit;
}
}

Related

The option "filters" does not have a callable "setFilters" ("setfilters") setter method

Environment:
"require": {
"php": "5.6",
"zendframework/zendframework": "2.5.0",
"zendframework/zend-servicemanager": "2.5.1",
"zendframework/zend-developer-tools": "1.0.0",
"doctrine/doctrine-orm-module": "0.9.2",
"acelaya/zf2-acmailer": "4.*",
"tasmaniski/zend-params-helper": "^1.0"
}
Fatal error: Uncaught exception 'Zend\Stdlib\Exception\BadMethodCallException' with message 'The option "filters" does not have a callable "setFilters" ("setfilters") setter method which must be defined' in C:\OSPanel\domains\csmCrew_github\vendor\zendframework\zend-servicemanager\src\ServiceManager.php on line 1135
I am trying to add SQL filter using this DareDevels tutorial
my interface: VacanciesFilterInterface.php
namespace Common\DoctrineFilter;
Interface VacanciesFilterInterface
{
public function setFilters($filters);
}
my filter class: VacanciesFilter.php
namespace Common\DoctrineFilter;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;
class VacanciesFilter extends SQLFilter
{
/**
* Gets the SQL query part to add to a query.
*
* #param ClassMetaData $targetEntity
* #param string $targetTableAlias
*
* #return string The constraint SQL if there is available, empty string otherwise.
*/
public function addFilterConstraint (ClassMetadata $targetEntity, $targetTableAlias)
{
// Check if the entity implements the LocalAware interface
if (!$targetEntity->reflClass->implementsInterface('\Common\DoctrineFilter\VacanciesFilterInterface')) {
return '';
}
return $targetTableAlias.'.Vacancies = ' . $this->getParameter('Vacancies'); // getParameter applies quoting automatically
}
my module.config.php:
'doctrine' => array(
'driver' => array(
// defines an annotation driver with two paths, and names it `my_annotation_driver`
'common_entity' => array(
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/Common/Entity',
__DIR__ . '/../src/Common/Entity/Repository',
),
),
// default metadata driver, aggregates all other drivers into a single one.
// Override `orm_default` only if you know what you're doing
'orm_default' => array(
'drivers' => array(
// register `my_annotation_driver` for any entity under namespace `My\Namespace`
'Common\Entity' => 'common_entity',
),
'filters' => array(
'vacancies' => 'Common\DoctrineFilter\VacanciesFilter',
),
),
),
),
I add filter in my controller using these methods:
public function enableVacanciesFilter()
{
$em = $this->getEntityManager();
$filter = $em->getFilters()->enable('vacancies');
$filter->setParameter('vacancies', '41');
}
/**
* Disable locale filter
*/
public function disableVacanciesFilter()
{
$em = $this->getEntityManager();
$filter = $em->getFilters()->disable('vacancies');
}
So the question is: how can I implement that callable setFilters setter method ?
I have tried to implement Interface in my Entity:
<?php
namespace Common\Entity;
use Common\DoctrineFilter\VacanciesFilterInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Vacancies
*
* #ORM\Table(name="vacancies", indexes={#ORM\Index(name="RankId_fk", columns={"rank_id"}), #ORM\Index(name="id", columns={"id"}), #ORM\Index(name="FK_vacancies_crewing_companies", columns={"company_id"}), #ORM\Index(name="FK_vacancies_vessels", columns={"vessel_id"}), #ORM\Index(name="FK_vacancies_vacancy_positions", columns={"position"}), #ORM\Index(name="status_id", columns={"status_id"})})
* #ORM\Entity
*/
class Vacancies implements VacanciesFilterInterface
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=128, nullable=false)
*/
private $title = '';
/**
* #var string
*
* #ORM\Column(name="additional_info", type="string", length=255, nullable=false)
*/
private $additionalInfo = '';
/**
* #var integer
*
* #ORM\Column(name="duration_of_contract_in_months", type="smallint", nullable=false)
*/
private $durationOfContractInMonths;
/**
* #var \DateTime
*
* #ORM\Column(name="joining_date", type="date", nullable=false)
*/
private $joiningDate;
/**
* #var integer
*
* #ORM\Column(name="salary_per_month", type="integer", nullable=false)
*/
private $salaryPerMonth;
/**
* #var boolean
*
* #ORM\Column(name="required_age_from", type="boolean", nullable=false)
*/
private $requiredAgeFrom;
/**
* #var boolean
*
* #ORM\Column(name="required_age_to", type="boolean", nullable=false)
*/
private $requiredAgeTo;
/**
* #var \DateTime
*
* #ORM\Column(name="creation_date", type="datetime", nullable=false)
*/
private $creationDate;
/**
* #var integer
*
* #ORM\Column(name="views_count", type="integer", nullable=true)
*/
private $viewsCount = '0';
/**
* #var integer
*
* #ORM\Column(name="job_seekers_applied", type="integer", nullable=true)
*/
private $jobSeekersApplied = '0';
/**
* #var boolean
*
* #ORM\Column(name="is_published", type="boolean", nullable=false)
*/
private $isPublished = '0';
/**
* #var \Common\Entity\CrewingCompanies
*
* #ORM\ManyToOne(targetEntity="Common\Entity\CrewingCompanies")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="company_id", referencedColumnName="id")
* })
*/
private $company;
/**
* #var \Common\Entity\VacancyPositions
*
* #ORM\ManyToOne(targetEntity="Common\Entity\VacancyPositions")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="position", referencedColumnName="id")
* })
*/
private $position;
/**
* #var \Common\Entity\Vessels
*
* #ORM\ManyToOne(targetEntity="Common\Entity\Vessels")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="vessel_id", referencedColumnName="id")
* })
*/
private $vessel;
/**
* #var \Common\Entity\Ranks
*
* #ORM\ManyToOne(targetEntity="Common\Entity\Ranks")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="rank_id", referencedColumnName="id")
* })
*/
private $rank;
/**
* #var \Common\Entity\VacancyStatuses
*
* #ORM\ManyToOne(targetEntity="Common\Entity\VacancyStatuses")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="status_id", referencedColumnName="id")
* })
*/
private $status;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Vacancies
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set additionalInfo
*
* #param string $additionalInfo
*
* #return Vacancies
*/
public function setAdditionalInfo($additionalInfo)
{
$this->additionalInfo = $additionalInfo;
return $this;
}
/**
* Get additionalInfo
*
* #return string
*/
public function getAdditionalInfo()
{
return $this->additionalInfo;
}
/**
* Set durationOfContractInMonths
*
* #param integer $durationOfContractInMonths
*
* #return Vacancies
*/
public function setDurationOfContractInMonths($durationOfContractInMonths)
{
$this->durationOfContractInMonths = $durationOfContractInMonths;
return $this;
}
/**
* Get durationOfContractInMonths
*
* #return integer
*/
public function getDurationOfContractInMonths()
{
return $this->durationOfContractInMonths;
}
/**
* Set joiningDate
*
* #param \DateTime $joiningDate
*
* #return Vacancies
*/
public function setJoiningDate($joiningDate)
{
$this->joiningDate = $joiningDate;
return $this;
}
/**
* Get joiningDate
*
* #return \DateTime
*/
public function getJoiningDate()
{
return $this->joiningDate;
}
/**
* Set salaryPerMonth
*
* #param integer $salaryPerMonth
*
* #return Vacancies
*/
public function setSalaryPerMonth($salaryPerMonth)
{
$this->salaryPerMonth = $salaryPerMonth;
return $this;
}
/**
* Get salaryPerMonth
*
* #return integer
*/
public function getSalaryPerMonth()
{
return $this->salaryPerMonth;
}
/**
* Set requiredAgeFrom
*
* #param boolean $requiredAgeFrom
*
* #return Vacancies
*/
public function setRequiredAgeFrom($requiredAgeFrom)
{
$this->requiredAgeFrom = $requiredAgeFrom;
return $this;
}
/**
* Get requiredAgeFrom
*
* #return boolean
*/
public function getRequiredAgeFrom()
{
return $this->requiredAgeFrom;
}
/**
* Set requiredAgeTo
*
* #param boolean $requiredAgeTo
*
* #return Vacancies
*/
public function setRequiredAgeTo($requiredAgeTo)
{
$this->requiredAgeTo = $requiredAgeTo;
return $this;
}
/**
* Get requiredAgeTo
*
* #return boolean
*/
public function getRequiredAgeTo()
{
return $this->requiredAgeTo;
}
/**
* Set creationDate
*
* #param \DateTime $creationDate
*
* #return Vacancies
*/
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
return $this;
}
/**
* Get creationDate
*
* #return \DateTime
*/
public function getCreationDate()
{
return $this->creationDate;
}
/**
* Set viewsCount
*
* #param integer $viewsCount
*
* #return Vacancies
*/
public function setViewsCount($viewsCount)
{
$this->viewsCount = $viewsCount;
return $this;
}
/**
* Get viewsCount
*
* #return integer
*/
public function getViewsCount()
{
return $this->viewsCount;
}
/**
* Set jobSeekersApplied
*
* #param integer $jobSeekersApplied
*
* #return Vacancies
*/
public function setJobSeekersApplied($jobSeekersApplied)
{
$this->jobSeekersApplied = $jobSeekersApplied;
return $this;
}
/**
* Get jobSeekersApplied
*
* #return integer
*/
public function getJobSeekersApplied()
{
return $this->jobSeekersApplied;
}
/**
* Set isPublished
*
* #param boolean $isPublished
*
* #return Vacancies
*/
public function setIsPublished($isPublished)
{
$this->isPublished = $isPublished;
return $this;
}
/**
* Get isPublished
*
* #return boolean
*/
public function getIsPublished()
{
return $this->isPublished;
}
/**
* Set company
*
* #param \Common\Entity\CrewingCompanies $company
*
* #return Vacancies
*/
public function setCompany(\Common\Entity\CrewingCompanies $company = null)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* #return \Common\Entity\CrewingCompanies
*/
public function getCompany()
{
return $this->company;
}
/**
* Set position
*
* #param \Common\Entity\VacancyPositions $position
*
* #return Vacancies
*/
public function setPosition(\Common\Entity\VacancyPositions $position = null)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* #return \Common\Entity\VacancyPositions
*/
public function getPosition()
{
return $this->position;
}
/**
* Set vessel
*
* #param \Common\Entity\Vessels $vessel
*
* #return Vacancies
*/
public function setVessel(\Common\Entity\Vessels $vessel = null)
{
$this->vessel = $vessel;
return $this;
}
/**
* Get vessel
*
* #return \Common\Entity\Vessels
*/
public function getVessel()
{
return $this->vessel;
}
/**
* Set rank
*
* #param \Common\Entity\Ranks $rank
*
* #return Vacancies
*/
public function setRank(\Common\Entity\Ranks $rank = null)
{
$this->rank = $rank;
return $this;
}
/**
* Get rank
*
* #return \Common\Entity\Ranks
*/
public function getRank()
{
return $this->rank;
}
/**
* Set status
*
* #param \Common\Entity\VacancyStatuses $status
*
* #return Vacancies
*/
public function setStatus(\Common\Entity\VacancyStatuses $status = null)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return \Common\Entity\VacancyStatuses
*/
public function getStatus()
{
return $this->status;
}
public function setFilters ($filters)
{
$this->filters = $filters;
// TODO: Implement setFilters() method.
}
}
But nothing helps to deal with that error.

Symfony2 / Doctrine, A new entity was found through the relationship

trying to fix this over 48 hours. I have an entity BookingRequest.php which content is:
<?php
namespace Kutiwa\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* BookingRequest
*
* #ORM\Table(name="booking_request")
* #ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\Repository\BookingRequestRepository")
*/
class BookingRequest
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="code", type="string", length=255, unique=true)
*/
private $code;
/**
* #var string
*
* #ORM\Column(name="arrival", type="string", length=255)
*/
private $arrival;
/**
* #var string
*
* #ORM\Column(name="departure", type="string", length=255)
*/
private $departure;
/**
* #var string
*
* #ORM\Column(name="requestDate", type="string", length=255)
*/
private $requestDate;
/**
* #var int
*
* #ORM\Column(name="rooms", type="integer")
*/
private $rooms;
/**
* #var string
*
* #ORM\Column(name="minPricing", type="string", length=255)
*/
private $minPricing;
/**
* #var string
*
* #ORM\Column(name="maxPricing", type="string", length=255)
*/
private $maxPricing;
/**
* #var string
*
* #ORM\Column(name="customerName", type="string", length=255)
*/
private $customerName;
/**
* #var string
*
* #ORM\Column(name="customerEmail", type="string", length=255, nullable=true)
*/
private $customerEmail;
/**
* #var string
*
* #ORM\Column(name="customerPhone", type="string", length=255)
*/
private $customerPhone;
/**
* #ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\City")
* #ORM\JoinColumn(nullable=false)
*/
private $destinationCity;
/**
* #ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\City")
* #ORM\JoinColumn(nullable=false)
*/
private $customerCity;
/**
* #ORM\OneToOne(targetEntity="Kutiwa\PlatformBundle\Entity\MissionConfig", cascade={"persist"})
*/
private $missionConfig;
/**
* #ORM\OneToOne(targetEntity="Kutiwa\PlatformBundle\Entity\TourismConfig", cascade={"persist"})
*/
private $tourismConfig;
/**
* #ORM\OneToMany(targetEntity="Kutiwa\PlatformBundle\Entity\RoomsConfig", mappedBy="bookingRequest")
*/
private $roomsConfigs;
public function __construct() {
$this->setRequestDate(date("d/m/Y"));
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set code
*
* #param string $code
*
* #return BookingRequest
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set arrival
*
* #param string $arrival
*
* #return BookingRequest
*/
public function setArrival($arrival)
{
$this->arrival = $arrival;
return $this;
}
/**
* Get arrival
*
* #return string
*/
public function getArrival()
{
return $this->arrival;
}
/**
* Set departure
*
* #param string $departure
*
* #return BookingRequest
*/
public function setDeparture($departure)
{
$this->departure = $departure;
return $this;
}
/**
* Get departure
*
* #return string
*/
public function getDeparture()
{
return $this->departure;
}
/**
* Set requestDate
*
* #param string $requestDate
*
* #return BookingRequest
*/
public function setRequestDate($requestDate)
{
$this->requestDate = $requestDate;
return $this;
}
/**
* Get requestDate
*
* #return string
*/
public function getRequestDate()
{
return $this->requestDate;
}
/**
* Set rooms
*
* #param integer $rooms
*
* #return BookingRequest
*/
public function setRooms($rooms)
{
$this->rooms = $rooms;
return $this;
}
/**
* Get rooms
*
* #return integer
*/
public function getRooms()
{
return $this->rooms;
}
/**
* Set minPricing
*
* #param string $minPricing
*
* #return BookingRequest
*/
public function setMinPricing($minPricing)
{
$this->minPricing = $minPricing;
return $this;
}
/**
* Get minPricing
*
* #return string
*/
public function getMinPricing()
{
return $this->minPricing;
}
/**
* Set maxPricing
*
* #param string $maxPricing
*
* #return BookingRequest
*/
public function setMaxPricing($maxPricing)
{
$this->maxPricing = $maxPricing;
return $this;
}
/**
* Get maxPricing
*
* #return string
*/
public function getMaxPricing()
{
return $this->maxPricing;
}
/**
* Set customerName
*
* #param string $customerName
*
* #return BookingRequest
*/
public function setCustomerName($customerName)
{
$this->customerName = $customerName;
return $this;
}
/**
* Get customerName
*
* #return string
*/
public function getCustomerName()
{
return $this->customerName;
}
/**
* Set customerEmail
*
* #param string $customerEmail
*
* #return BookingRequest
*/
public function setCustomerEmail($customerEmail)
{
$this->customerEmail = $customerEmail;
return $this;
}
/**
* Get customerEmail
*
* #return string
*/
public function getCustomerEmail()
{
return $this->customerEmail;
}
/**
* Set customerPhone
*
* #param string $customerPhone
*
* #return BookingRequest
*/
public function setCustomerPhone($customerPhone)
{
$this->customerPhone = $customerPhone;
return $this;
}
/**
* Get customerPhone
*
* #return string
*/
public function getCustomerPhone()
{
return $this->customerPhone;
}
/**
* Set destinationCity
*
* #param \Kutiwa\PlatformBundle\Entity\City $destinationCity
*
* #return BookingRequest
*/
public function setDestinationCity(\Kutiwa\PlatformBundle\Entity\City $destinationCity)
{
$this->destinationCity = $destinationCity;
return $this;
}
/**
* Get destinationCity
*
* #return \Kutiwa\PlatformBundle\Entity\City
*/
public function getDestinationCity()
{
return $this->destinationCity;
}
/**
* Set customerCity
*
* #param \Kutiwa\PlatformBundle\Entity\City $customerCity
*
* #return BookingRequest
*/
public function setCustomerCity(\Kutiwa\PlatformBundle\Entity\City $customerCity)
{
$this->customerCity = $customerCity;
return $this;
}
/**
* Get customerCity
*
* #return \Kutiwa\PlatformBundle\Entity\City
*/
public function getCustomerCity()
{
return $this->customerCity;
}
/**
* Set missionConfig
*
* #param \Kutiwa\PlatformBundle\Entity\MissionConfig $missionConfig
*
* #return BookingRequest
*/
public function setMissionConfig(\Kutiwa\PlatformBundle\Entity\MissionConfig $missionConfig = null)
{
$this->missionConfig = $missionConfig;
return $this;
}
/**
* Get missionConfig
*
* #return \Kutiwa\PlatformBundle\Entity\MissionConfig
*/
public function getMissionConfig()
{
return $this->missionConfig;
}
/**
* Set tourismConfig
*
* #param \Kutiwa\PlatformBundle\Entity\TourismConfig $tourismConfig
*
* #return BookingRequest
*/
public function setTourismConfig(\Kutiwa\PlatformBundle\Entity\TourismConfig $tourismConfig = null)
{
$this->tourismConfig = $tourismConfig;
return $this;
}
/**
* Get tourismConfig
*
* #return \Kutiwa\PlatformBundle\Entity\TourismConfig
*/
public function getTourismConfig()
{
return $this->tourismConfig;
}
/**
* Add roomsConfig
*
* #param \Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig
*
* #return BookingRequest
*/
public function addRoomsConfig(\Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig)
{
$this->roomsConfigs[] = $roomsConfig;
return $this;
}
/**
* Remove roomsConfig
*
* #param \Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig
*/
public function removeRoomsConfig(\Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig)
{
$this->roomsConfigs->removeElement($roomsConfig);
}
/**
* Get roomsConfigs
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getRoomsConfigs()
{
return $this->roomsConfigs;
}
}
and another entity RoomsConfig.php
<?php
namespace Kutiwa\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* RoomsConfig
*
* #ORM\Table(name="rooms_config")
* #ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\Repository\RoomsConfigRepository")
*/
class RoomsConfig
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var bool
*
* #ORM\Column(name="airConditionner", type="boolean")
*/
private $airConditionner;
/**
* #var bool
*
* #ORM\Column(name="wifi", type="boolean")
*/
private $wifi;
/**
* #var bool
*
* #ORM\Column(name="balcony", type="boolean")
*/
private $balcony;
/**
* #var string
*
* #ORM\Column(name="tv", type="boolean")
*/
private $tv;
/**
* #ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\BookingRequest", inversedBy="roomsConfigs", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $bookingRequest;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set airConditionner
*
* #param boolean $airConditionner
*
* #return RoomsConfig
*/
public function setAirConditionner($airConditionner)
{
$this->airConditionner = $airConditionner;
return $this;
}
/**
* Get airConditionner
*
* #return boolean
*/
public function getAirConditionner()
{
return $this->airConditionner;
}
/**
* Set wifi
*
* #param boolean $wifi
*
* #return RoomsConfig
*/
public function setWifi($wifi)
{
$this->wifi = $wifi;
return $this;
}
/**
* Get wifi
*
* #return boolean
*/
public function getWifi()
{
return $this->wifi;
}
/**
* Set balcony
*
* #param boolean $balcony
*
* #return RoomsConfig
*/
public function setBalcony($balcony)
{
$this->balcony = $balcony;
return $this;
}
/**
* Get balcony
*
* #return boolean
*/
public function getBalcony()
{
return $this->balcony;
}
/**
* Set tv
*
* #param boolean $tv
*
* #return RoomsConfig
*/
public function setTv($tv)
{
$this->tv = $tv;
return $this;
}
/**
* Get tv
*
* #return boolean
*/
public function getTv()
{
return $this->tv;
}
/**
* Set bookingRequest
*
* #param \Kutiwa\PlatformBundle\Entity\BookingRequest $bookingRequest
*
* #return RoomsConfig
*/
public function setBookingRequest(\Kutiwa\PlatformBundle\Entity\BookingRequest $bookingRequest)
{
$this->bookingRequest = $bookingRequest;
$bookingRequest->addRoomsConfig($this);
return $this;
}
/**
* Get bookingRequest
*
* #return \Kutiwa\PlatformBundle\Entity\BookingRequest
*/
public function getBookingRequest()
{
return $this->bookingRequest;
}
}
The problem is, when I try to persist a RoomsConfig entity, I got an error
A new entity was found through the relationship
'Kutiwa\PlatformBundle\Entity\BookingRequest#destinationCity' that was
not configured to cascade persist operations for entity: TIKO. To
solve this issue: Either explicitly call EntityManager#persist() on
this unknown entity or configure cascade persist this association in
the mapping for example #ManyToOne(..,cascade={"persist"})
I don't need a cascade effect on City and BookingRequest relation, here is my BookingRequestType.php
<?php
namespace Kutiwa\PlatformBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BookingRequestType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('arrival', TextType::class)
->add('departure', TextType::class)
->add('rooms', IntegerType::class)
->add('customerName', TextType::class)
->add('customerEmail', TextType::class, array('required' => false))
->add('customerPhone', TextType::class)
->add('destinationCity', EntityType::class, array(
'choice_label' => 'name',
'class' => 'KutiwaPlatformBundle:City'
))
->add('customerCity', EntityType::class, array(
'choice_label' => 'name',
'class' => 'KutiwaPlatformBundle:City'
));
}
/**
* {#inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Kutiwa\PlatformBundle\Entity\BookingRequest'
));
}
/**
* {#inheritdoc}
*/
public function getBlockPrefix()
{
return 'kutiwa_platformbundle_bookingrequest';
}
}
If I try to persist only BookingRequest entity, there is no problem, but when I persist RoomsConfig entity, I got that error. Help please. Thks.
Before persist your RoomsConfig, try to use findOneBy to find BookingRequest, or whatever you use to find the entity, and then set the found entity with setBookingRequest.

Fill Selectbox with database data - Forms + Doctrine + Symfony 3

I am trying to populate my form with an List of Results from query with Doctrine
But i`m getting this error:
Catchable Fatal Error: Object of class AppBundle\Entity\Parceiros could not be converted to string
Here is my Form CoberturasType
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class CoberturasType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('descricao')
->add('parceiro', EntityType::class, [
'class'=>'AppBundle:Parceiros',
])
;
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Coberturas'
));
}
}
Here is my CoberturasEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Coberturas
*
* #ORM\Table(name="coberturas")
* #ORM\Entity(repositoryClass="AppBundle\Repository\CoberturasRepository")
* #ORM\Entity()
* #ORM\HasLifecycleCallbacks()
*/
class Coberturas
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Parceiros")
* #ORM\JoinColumn(name="parceiro", referencedColumnName="id", nullable=false)
*/
protected $parceiro;
/**
* #var string
*
* #ORM\Column(name="descricao", type="string", length=120)
*/
private $descricao;
/**
* #var bool
*
* #ORM\Column(name="_ativo", type="boolean")
*/
private $ativo;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #var string
*
* #ORM\Column(name="updated", type="datetime")
*/
private $updated;
/**
* #var bool
*
* #ORM\Column(name="_deletado", type="boolean")
*/
private $deletado;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set descricao
*
* #param string $descricao
*
* #return Coberturas
*/
public function setDescricao($descricao)
{
$this->descricao = $descricao;
return $this;
}
/**
* Get descricao
*
* #return string
*/
public function getDescricao()
{
return $this->descricao;
}
/**
* Set ativo
*
* #param boolean $ativo
*
* #return Coberturas
*/
public function setAtivo($ativo)
{
$this->ativo = $ativo;
return $this;
}
/**
* Get ativo
*
* #return bool
*/
public function getAtivo()
{
return $this->ativo;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Coberturas
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param string $updated
*
* #return Coberturas
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return string
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set deletado
*
* #param boolean $deletado
*
* #return Coberturas
*/
public function setDeletado($deletado)
{
$this->deletado = $deletado;
return $this;
}
/**
* Get deletado
*
* #return bool
*/
public function getDeletado()
{
return $this->deletado;
}
/**
* #ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
/**
* #ORM\postUpdate
*/
public function setUpdatedValue()
{
$this->updated = new \DateTime();
}
/**
* Set parceiro
*
* #param \AppBundle\Entity\Parceiros $parceiro
*
* #return Coberturas
*/
public function setParceiro(\AppBundle\Entity\Parceiros $parceiro = null)
{
$this->parceiro = $parceiro;
return $this;
}
/**
* Get parceiro
*
* #return \AppBundle\Entity\Parceiros
*/
public function getParceiro()
{
return $this->parceiro;
}
}
Here is my ParceirosEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Parceiros
*
* #ORM\Table(name="parceiros")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ParceirosRepository")
* #ORM\Entity()
* #ORM\HasLifecycleCallbacks()
*/
class Parceiros
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\OneToMany(targetEntity="Coberturas", mappedBy="parceiro")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="razaoSocial", type="string", length=255)
*/
private $razaoSocial;
/**
* #var string
*
* #ORM\Column(name="nomeFantasia", type="string", length=255, nullable=true)
*/
private $nomeFantasia;
/**
* #var string
*
* #ORM\Column(name="cnpj", type="string", length=17, nullable=true)
*/
private $cnpj;
/**
* #var string
*
* #ORM\Column(name="inscEstadual", type="string", length=60, nullable=true)
*/
private $inscEstadual;
/**
* #var string
*
* #ORM\Column(name="cep", type="string", length=9, nullable=true)
*/
private $cep;
/**
* #var string
*
* #ORM\Column(name="endereco", type="string", length=160, nullable=true)
*/
private $endereco;
/**
* #var string
*
* #ORM\Column(name="numero", type="string", length=30, nullable=true)
*/
private $numero;
/**
* #var string
*
* #ORM\Column(name="complemento", type="string", length=30, nullable=true)
*/
private $complemento;
/**
* #var string
*
* #ORM\Column(name="bairro", type="string", length=80, nullable=true)
*/
private $bairro;
/**
* #var string
*
* #ORM\Column(name="cidade", type="string", length=100, nullable=true)
*/
private $cidade;
/**
* #var string
*
* #ORM\Column(name="estado", type="string", length=2, nullable=true)
*/
private $estado;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime", nullable=true)
*/
private $created;
/**
* #var \DateTime
*
* #ORM\Column(name="updated", type="datetime", nullable=true)
*/
private $updated;
/**
* #var bool
*
* #ORM\Column(name="ativo", type="boolean", nullable=true)
*/
private $ativo = 1;
/**
* #var bool
*
* #ORM\Column(name="deletado", type="boolean", nullable=true)
*/
private $deletado = 0;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set razaoSocial
*
* #param string $razaoSocial
*
* #return Parceiros
*/
public function setRazaoSocial($razaoSocial)
{
$this->razaoSocial = $razaoSocial;
return $this;
}
/**
* Get razaoSocial
*
* #return string
*/
public function getRazaoSocial()
{
return $this->razaoSocial;
}
/**
* Set nomeFantasia
*
* #param string $nomeFantasia
*
* #return Parceiros
*/
public function setNomeFantasia($nomeFantasia)
{
$this->nomeFantasia = $nomeFantasia;
return $this;
}
/**
* Get nomeFantasia
*
* #return string
*/
public function getNomeFantasia()
{
return $this->nomeFantasia;
}
/**
* Set cnpj
*
* #param string $cnpj
*
* #return Parceiros
*/
public function setCnpj($cnpj)
{
$this->cnpj = $cnpj;
return $this;
}
/**
* Get cnpj
*
* #return string
*/
public function getCnpj()
{
return $this->cnpj;
}
/**
* Set inscEstadual
*
* #param string $inscEstadual
*
* #return Parceiros
*/
public function setInscEstadual($inscEstadual)
{
$this->inscEstadual = $inscEstadual;
return $this;
}
/**
* Get inscEstadual
*
* #return string
*/
public function getInscEstadual()
{
return $this->inscEstadual;
}
/**
* Set cep
*
* #param string $cep
*
* #return Parceiros
*/
public function setCep($cep)
{
$this->cep = $cep;
return $this;
}
/**
* Get cep
*
* #return string
*/
public function getCep()
{
return $this->cep;
}
/**
* Set endereco
*
* #param string $endereco
*
* #return Parceiros
*/
public function setEndereco($endereco)
{
$this->endereco = $endereco;
return $this;
}
/**
* Get endereco
*
* #return string
*/
public function getEndereco()
{
return $this->endereco;
}
/**
* Set numero
*
* #param string $numero
*
* #return Parceiros
*/
public function setNumero($numero)
{
$this->numero = $numero;
return $this;
}
/**
* Get numero
*
* #return string
*/
public function getNumero()
{
return $this->numero;
}
/**
* Set complemento
*
* #param string $complemento
*
* #return Parceiros
*/
public function setComplemento($complemento)
{
$this->complemento = $complemento;
return $this;
}
/**
* Get complemento
*
* #return string
*/
public function getComplemento()
{
return $this->complemento;
}
/**
* Set bairro
*
* #param string $bairro
*
* #return Parceiros
*/
public function setBairro($bairro)
{
$this->bairro = $bairro;
return $this;
}
/**
* Get bairro
*
* #return string
*/
public function getBairro()
{
return $this->bairro;
}
/**
* Set cidade
*
* #param string $cidade
*
* #return Parceiros
*/
public function setCidade($cidade)
{
$this->cidade = $cidade;
return $this;
}
/**
* Get cidade
*
* #return string
*/
public function getCidade()
{
return $this->cidade;
}
/**
* Set estado
*
* #param string $estado
*
* #return Parceiros
*/
public function setEstado($estado)
{
$this->estado = $estado;
return $this;
}
/**
* Get estado
*
* #return string
*/
public function getEstado()
{
return $this->estado;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Parceiros
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param \DateTime $updated
*
* #return Parceiros
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set ativo
*
* #param boolean $ativo
*
* #return Parceiros
*/
public function setAtivo($ativo)
{
$this->ativo = $ativo;
return $this;
}
/**
* Get ativo
*
* #return bool
*/
public function getAtivo()
{
return $this->ativo;
}
/**
* Set deletado
*
* #param boolean $deletado
*
* #return Parceiros
*/
public function setDeletado($deletado)
{
$this->deletado = $deletado;
return $this;
}
/**
* Get deletado
*
* #return bool
*/
public function getDeletado()
{
return $this->deletado;
}
/**
* #ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
/**
* #ORM\postUpdate
*/
public function setUpdatedValue()
{
$this->updated = new \DateTime();
}
}
I just wanna show an SelectBox to user select for what "parceiro" he wanna insert a new "cobertura".
Thanks for the help...

ZF2 Doctrine get manytomany relations with objectSelect

I have multiple users, with multiple stores in a many to many relational database. Every user has multiple stores attached to them.
Now, i want to load all the storenames from a logged in user in a select form.
How can i do this?
My user entity:
namespace Application\Entity;
use BjyAuthorize\Provider\Role\ProviderInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ZfcUser\Entity\UserInterface;
/**
* An example of how to implement a role aware user entity.
*
* #ORM\Entity
* #ORM\Table(name="users")
* #ORM\Entity(repositoryClass="Application\Repositories\UserRepository")
*
*/
class User implements UserInterface, ProviderInterface
{
/**
* #var int
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
* #ORM\Column(type="string", length=255, unique=true, nullable=true)
*/
protected $username;
/**
* #var string
* #ORM\Column(type="string", unique=true, length=255)
*/
protected $email;
/**
* #var string
* #ORM\Column(type="string", length=50, nullable=true)
*/
protected $displayName;
/**
* #var string
* #ORM\Column(type="string", length=128)
*/
protected $password;
/**
* #var int
*/
protected $state;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Role")
* #ORM\JoinTable(name="user_role_linker",
* joinColumns={#ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $roles;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Store")
* #ORM\JoinTable(name="user_store_linker",
* joinColumns={#ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="store_id", referencedColumnName="id")}
* )
*/
protected $stores;
/**
* Initialies the roles variable.
*/
public function __construct()
{
$this->roles = new ArrayCollection();
$this->stores = new ArrayCollection();
}
/**
* Get id.
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* #param int $id
*
* #return void
*/
public function setId($id)
{
$this->id = (int) $id;
}
/**
* Get username.
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set username.
*
* #param string $username
*
* #return void
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Get email.
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set email.
*
* #param string $email
*
* #return void
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get displayName.
*
* #return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* Set displayName.
*
* #param string $displayName
*
* #return void
*/
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
}
/**
* Get password.
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set password.
*
* #param string $password
*
* #return void
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get state.
*
* #return int
*/
public function getState()
{
return $this->state;
}
/**
* Set state.
*
* #param int $state
*
* #return void
*/
public function setState($state)
{
$this->state = $state;
}
/**
* Get role.
*
* #return array
*/
public function getRoles()
{
return $this->roles->getValues();
}
/**
* Add a role to the user.
*
* #param Role $role
*
* #return void
*/
public function addRole($role)
{
$this->roles[] = $role;
}
/**
* Get store.
*
* #return array
*/
public function getStores()
{
return $this->stores;
}
/**
* Get store.
*
* #return array
*/
public function getStore($id)
{
return $this->stores[$id]->getValues();
}
/**
* Add a store to the user.
*
* #param Role $store
*
* #return void
*/
public function addStore($store)
{
$this->stores[] = $store;
}
}
My store Entity:
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* An example entity that represents a store.
*
* #ORM\Entity
* #ORM\Table(name="store")
*
*/
class Store
{
/**
* #var int
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
* #ORM\Column(type="string", name="storeName", length=255, unique=true, nullable=true)
*/
protected $storeName;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Product" )
*/
protected $products;
/**
* Initialies the roles variable.
*/
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* Get the id.
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set the id.
*
* #param int $id
*
* #return void
*/
public function setId($id)
{
$this->id = (int)$id;
}
/**
* Get the store id.
*
* #return string
*/
public function getStoreName()
{
return $this->storeName;
}
/**
* Set the store id.
*
* #param string $storeName
*
* #return void
*/
public function setStoreName($storeName)
{
$this->storeName = (string) $storeName;
}
/**
* Get product.
*
* #return array
*/
public function getProducts()
{
return $this->products->getValues();
}
/**
* Add a product to the user.
*
* #param Role $product
*
* #return void
*/
public function addProduct($products)
{
$this->products[] = $products;
}
}
My form:
$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'name' => 'stores',
'attributes' => array(
'multiple' => true,
),
'options' => array(
'object_manager' => $objectManager,
'target_class' => 'Application\Entity\User',
'label' => 'Selecteer winkel',
'column-size' => 'sm-9',
'label_attributes' => array('class' => 'col-sm-3 control-label'),
'property' => 'stores',
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array('id' => $userid)
),
),
'is_method' => true,
),
));
I'm getting this message:
File:
zend/vendor/zendframework/zendframework/library/Zend/View/Helper/Escaper/AbstractHelper.php:70
Message:
Object provided to Escape helper, but flags do not allow recursion
Anyone?
Ok i've figured it out with a custom repository.
Add a repositoryclass to your store entity
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
*
* #ORM\Entity
* #ORM\Table(name="store")
* #ORM\Entity(repositoryClass="Application\Repositories\StoreRepository")
*
*/
class Store
{
/**
* #var int
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
* #ORM\Column(type="string", name="storeName", length=255, unique=true, nullable=true)
*/
protected $storeName;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Product", inversedBy="stores")
* #ORM\JoinTable(name="product_store")
*/
protected $products;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Category", inversedBy="stores")
* #ORM\JoinTable(name="category_store")
*/
protected $categories;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\User", inversedBy="stores")
* #ORM\JoinTable(name="user_store")
*/
protected $users;
/**
* Initialies the roles variable.
*/
public function __construct()
{
$this->products = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->users = new ArrayCollection();
}
/**
* Get the id.
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set the id.
*
* #param int $id
*
* #return void
*/
public function setId($id)
{
$this->id = (int)$id;
}
/**
* Get the store id.
*
* #return string
*/
public function getStoreName()
{
return $this->storeName;
}
/**
* Set the store id.
*
* #param string $storeName
*
* #return void
*/
public function setStoreName($storeName)
{
$this->storeName = (string) $storeName;
}
/**
* Get product.
*
* #return array
*/
public function getProducts()
{
return $this->products->getValues();
}
/**
* Add a product to the user.
*
* #param Role $product
*
* #return void
*/
public function addProduct($products)
{
$this->products[] = $products;
}
/**
* Get category.
*
* #return array
*/
public function getCategories()
{
return $this->categories->getValues();
}
/**
* Add a product to the user.
*
* #param Role $product
*
* #return void
*/
public function addCategory($categories)
{
$this->categories[] = $categories;
}
/**
* Get category.
*
* #return array
*/
public function getUsers()
{
return $this->users->getValues();
}
/**
* Add a product to the user.
*
* #param Role $product
*
* #return void
*/
public function addUser($users)
{
$this->users[] = $users;
}
}
My user entity
namespace Application\Entity;
use BjyAuthorize\Provider\Role\ProviderInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ZfcUser\Entity\UserInterface;
/**
*
* #ORM\Entity
* #ORM\Table(name="users")
* #ORM\Entity(repositoryClass="Application\Repositories\UserRepository")
*
*/
class User implements UserInterface, ProviderInterface
{
/**
* #var int
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
* #ORM\Column(type="string", length=255, unique=true, nullable=true)
*/
protected $username;
/**
* #var string
* #ORM\Column(type="string", unique=true, length=255)
*/
protected $email;
/**
* #var string
* #ORM\Column(type="string", length=50, nullable=true)
*/
protected $displayName;
/**
* #var string
* #ORM\Column(type="string", length=128)
*/
protected $password;
/**
* #var int
*/
protected $state;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Role")
* #ORM\JoinTable(name="user_role_linker",
* joinColumns={#ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $roles;
/**
* #var \Doctrine\Common\Collections\Collection
* #ORM\ManyToMany(targetEntity="Application\Entity\Store", mappedBy="users")
*/
protected $stores;
/**
* Initialies the roles variable.
*/
public function __construct()
{
$this->roles = new ArrayCollection();
$this->stores = new ArrayCollection();
}
/**
* Get id.
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* #param int $id
*
* #return void
*/
public function setId($id)
{
$this->id = (int) $id;
}
/**
* Get username.
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set username.
*
* #param string $username
*
* #return void
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Get email.
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set email.
*
* #param string $email
*
* #return void
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get displayName.
*
* #return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* Set displayName.
*
* #param string $displayName
*
* #return void
*/
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
}
/**
* Get password.
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set password.
*
* #param string $password
*
* #return void
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get state.
*
* #return int
*/
public function getState()
{
return $this->state;
}
/**
* Set state.
*
* #param int $state
*
* #return void
*/
public function setState($state)
{
$this->state = $state;
}
/**
* Get role.
*
* #return array
*/
public function getRoles()
{
return $this->roles->getValues();
}
/**
* Add a role to the user.
*
* #param Role $role
*
* #return void
*/
public function addRole($role)
{
$this->roles[] = $role;
}
/**
* Get store.
*
* #return array
*/
public function getStores()
{
return $this->stores;
}
/**
* Get store.
*
* #return array
*/
public function getStore($id)
{
return $this->stores[$id]->getValues();
}
/**
* Add a store to the user.
*
* #param Role $store
*
* #return void
*/
public function addStore($store)
{
$this->stores[] = $store;
}
}
The object select
$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'name' => 'stores',
'attributes' => array(
'multiple' => true,
),
'options' => array(
'object_manager' => $objectManager,
'target_class' => 'Application\Entity\Store',
'label' => 'Selecteer winkel',
'column-size' => 'sm-9',
'label_attributes' => array('class' => 'col-sm-3 control-label'),
'property' => 'storeName',
'is_method' => true,
'find_method' => array(
'name' => 'storesByUser',
'params' => array(
'criteria' => array('id' => $userid),
),
),
),
));
My custom store repository
<?php
namespace Application\Repositories;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\DBAL\Types\Type;
class StoreRepository extends EntityRepository
{
public function storesByUser(array $criteria){
return $this->createQueryBuilder('s')
->select('s')
->innerJoin("s.users", "u", "WITH", "u=:userid")
->setParameter("userid", $criteria['id'])
->getQuery()->getResult();
}
}

Add data from other table to form + Symfony2

I have a table users with different fields in it. And I also have a table players with a FK user_id in it (along other fields).
Now I have a registerForm to create a user, but I would also like to add a field for a player.
This is my form now:
$builder
->add('userFirstname', 'text', [
'label' => 'Given name',
'attr' => [
'placeholder' => 'Enter your given name.',
],
])
->add('userSurname', 'text', [
'label' => 'Family name',
'attr' => ['placeholder' => 'Enter your family name.'],
])
->add('userType', 'choice', array(
'choices' => array('E' => 'ENTHOUSIAST', 'P' => 'PLAYER', 'T' => 'TRAINER'),
'label' => 'User Type',
'attr' => array('placeholder' => 'User Type')
))
->add('player')
->add('userUsername', 'text', [
'label' => 'Username',
'attr' => ['placeholder' => 'Enter a username.'],
])
->add('userEmail', 'email', [
'label' => 'Email address',
'attr' => ['placeholder' => 'Enter your email address.'],
])
->add('userPassword', 'repeated', [
'type' => 'password',
'first_name' => 'password',
'first_options' => [
'label' => 'Password',
'attr' => ['placeholder' => 'Enter a password.'],
],
'second_name' => 'confirm',
'second_options' => [
'label' => 'Password (repeat)',
'attr' => ['placeholder' => 'Repeat the password.'],
],
'invalid_message' => 'The passwords are not identical.',
])
->add('btn_register', 'submit', [
'label' => 'Register',
])
;
In my players table I have 'player_birthyear'. How can I add this to my form? I already tried to add player.birthyear to my Form but didn't work.
UPDATE:
My Users entities class:
/**
* Users
*
* #ORM\Table(name="users", indexes={#ORM\Index(name="fk_users_roles1_idx", columns={"role_id"})})
* #ORM\Entity
*/
class Users
{
/**
* #var string
*
* #ORM\Column(name="user_username", type="string", length=45, nullable=false)
*/
private $userUsername;
/**
* #var string
*
* #ORM\Column(name="user_firstname", type="string", length=45, nullable=false)
*/
private $userFirstname;
/**
* #var string
*
* #ORM\Column(name="user_surname", type="string", length=255, nullable=false)
*/
private $userSurname;
/**
* #var string
*
* #ORM\Column(name="user_email", type="string", length=255, nullable=false)
*/
private $userEmail;
/**
* #var string
*
* #ORM\Column(name="user_type", type="string", nullable=false)
*/
private $userType;
/**
* #var string
*
* #ORM\Column(name="user_password", type="string", length=60, nullable=false)
*/
private $userPassword;
/**
* #var string
*
* #ORM\Column(name="user_salt", type="string", length=30, nullable=false)
*/
private $userSalt;
/**
* #var string
*
* #ORM\Column(name="user_token", type="string", length=45, nullable=true)
*/
private $userToken;
/**
* #var \DateTime
*
* #ORM\Column(name="user_created", type="datetime", nullable=false)
*/
private $userCreated;
/**
* #var \DateTime
*
* #ORM\Column(name="user_modified", type="datetime", nullable=true)
*/
private $userModified;
/**
* #var \DateTime
*
* #ORM\Column(name="user_deleted", type="datetime", nullable=true)
*/
private $userDeleted;
/**
* #var \DateTime
*
* #ORM\Column(name="user_lastlogin", type="datetime", nullable=true)
*/
private $userLastlogin;
/**
* #var \DateTime
*
* #ORM\Column(name="user_confirmed", type="datetime", nullable=true)
*/
private $userConfirmed;
/**
* #var \DateTime
*
* #ORM\Column(name="user_locked", type="datetime", nullable=true)
*/
private $userLocked;
/**
* #var integer
*
* #ORM\Column(name="user_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $userId;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Roles
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Roles")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="role_id", referencedColumnName="role_id")
* })
*/
private $role;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Teams", inversedBy="user")
* #ORM\JoinTable(name="user_follows_teams",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="team_id", referencedColumnName="team_id")
* }
* )
*/
private $team;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Competitions", inversedBy="user")
* #ORM\JoinTable(name="user_follows_competitions",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="competition_id", referencedColumnName="competition_id")
* }
* )
*/
private $competition;
/**
* Constructor
*/
public function __construct()
{
$this->team = new \Doctrine\Common\Collections\ArrayCollection();
$this->competition = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set userUsername
*
* #param string $userUsername
* #return Users
*/
public function setUserUsername($userUsername)
{
$this->userUsername = $userUsername;
return $this;
}
/**
* Get userUsername
*
* #return string
*/
public function getUserUsername()
{
return $this->userUsername;
}
/**
* Set userFirstname
*
* #param string $userFirstname
* #return Users
*/
public function setUserFirstname($userFirstname)
{
$this->userFirstname = $userFirstname;
return $this;
}
/**
* Get userFirstname
*
* #return string
*/
public function getUserFirstname()
{
return $this->userFirstname;
}
/**
* Set userSurname
*
* #param string $userSurname
* #return Users
*/
public function setUserSurname($userSurname)
{
$this->userSurname = $userSurname;
return $this;
}
/**
* Get userSurname
*
* #return string
*/
public function getUserSurname()
{
return $this->userSurname;
}
/**
* Set userEmail
*
* #param string $userEmail
* #return Users
*/
public function setUserEmail($userEmail)
{
$this->userEmail = $userEmail;
return $this;
}
/**
* Get userEmail
*
* #return string
*/
public function getUserEmail()
{
return $this->userEmail;
}
/**
* Set userType
*
* #param string $userType
* #return Users
*/
public function setUserType($userType)
{
$this->userType = $userType;
return $this;
}
/**
* Get userType
*
* #return string
*/
public function getUserType()
{
return $this->userType;
}
/**
* Set userPassword
*
* #param string $userPassword
* #return Users
*/
public function setUserPassword($userPassword)
{
$this->userPassword = $userPassword;
return $this;
}
/**
* Get userPassword
*
* #return string
*/
public function getUserPassword()
{
return $this->userPassword;
}
/**
* Set userSalt
*
* #param string $userSalt
* #return Users
*/
public function setUserSalt($userSalt)
{
$this->userSalt = $userSalt;
return $this;
}
/**
* Get userSalt
*
* #return string
*/
public function getUserSalt()
{
return $this->userSalt;
}
/**
* Set userToken
*
* #param string $userToken
* #return Users
*/
public function setUserToken($userToken)
{
$this->userToken = $userToken;
return $this;
}
/**
* Get userToken
*
* #return string
*/
public function getUserToken()
{
return $this->userToken;
}
/**
* Set userCreated
*
* #param \DateTime $userCreated
* #return Users
*/
public function setUserCreated($userCreated)
{
$this->userCreated = $userCreated;
return $this;
}
/**
* Get userCreated
*
* #return \DateTime
*/
public function getUserCreated()
{
return $this->userCreated;
}
/**
* Set userModified
*
* #param \DateTime $userModified
* #return Users
*/
public function setUserModified($userModified)
{
$this->userModified = $userModified;
return $this;
}
/**
* Get userModified
*
* #return \DateTime
*/
public function getUserModified()
{
return $this->userModified;
}
/**
* Set userDeleted
*
* #param \DateTime $userDeleted
* #return Users
*/
public function setUserDeleted($userDeleted)
{
$this->userDeleted = $userDeleted;
return $this;
}
/**
* Get userDeleted
*
* #return \DateTime
*/
public function getUserDeleted()
{
return $this->userDeleted;
}
/**
* Set userLastlogin
*
* #param \DateTime $userLastlogin
* #return Users
*/
public function setUserLastlogin($userLastlogin)
{
$this->userLastlogin = $userLastlogin;
return $this;
}
/**
* Get userLastlogin
*
* #return \DateTime
*/
public function getUserLastlogin()
{
return $this->userLastlogin;
}
/**
* Set userConfirmed
*
* #param \DateTime $userConfirmed
* #return Users
*/
public function setUserConfirmed($userConfirmed)
{
$this->userConfirmed = $userConfirmed;
return $this;
}
/**
* Get userConfirmed
*
* #return \DateTime
*/
public function getUserConfirmed()
{
return $this->userConfirmed;
}
/**
* Set userLocked
*
* #param \DateTime $userLocked
* #return Users
*/
public function setUserLocked($userLocked)
{
$this->userLocked = $userLocked;
return $this;
}
/**
* Get userLocked
*
* #return \DateTime
*/
public function getUserLocked()
{
return $this->userLocked;
}
/**
* Get userId
*
* #return integer
*/
public function getUserId()
{
return $this->userId;
}
/**
* Set role
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Roles $role
* #return Users
*/
public function setRole(\VolleyScout\VolleyScoutBundle\Entity\Roles $role = null)
{
$this->role = $role;
return $this;
}
/**
* Get role
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Roles
*/
public function getRole()
{
return $this->role;
}
/**
* Add team
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Teams $team
* #return Users
*/
public function addTeam(\VolleyScout\VolleyScoutBundle\Entity\Teams $team)
{
$this->team[] = $team;
return $this;
}
/**
* Remove team
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Teams $team
*/
public function removeTeam(\VolleyScout\VolleyScoutBundle\Entity\Teams $team)
{
$this->team->removeElement($team);
}
/**
* Get team
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getTeam()
{
return $this->team;
}
/**
* Add competition
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Competitions $competition
* #return Users
*/
public function addCompetition(\VolleyScout\VolleyScoutBundle\Entity\Competitions $competition)
{
$this->competition[] = $competition;
return $this;
}
/**
* Remove competition
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Competitions $competition
*/
public function removeCompetition(\VolleyScout\VolleyScoutBundle\Entity\Competitions $competition)
{
$this->competition->removeElement($competition);
}
/**
* Get competition
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCompetition()
{
return $this->competition;
}
}
My Players entities class:
/**
* Players
*
* #ORM\Table(name="players", indexes={#ORM\Index(name="fk_players_users1_idx", columns={"user_id"}), #ORM\Index(name="fk_players_teams1_idx", columns={"team_id"}), #ORM\Index(name="fk_players_myteam1_idx", columns={"myteam_id"})})
* #ORM\Entity
*/
class Players
{
/**
* #var string
*
* #ORM\Column(name="player_name", type="string", length=255, nullable=false)
*/
private $playerName;
/**
* #var string
*
* #ORM\Column(name="player_licensenumber", type="string", length=45, nullable=false)
*/
private $playerLicensenumber;
/**
* #var string
*
* #ORM\Column(name="player_position", type="string", nullable=false)
*/
private $playerPosition;
/**
* #var \DateTime
*
* #ORM\Column(name="player_birthyear", type="datetime", nullable=true)
*/
private $playerBirthyear;
/**
* #var integer
*
* #ORM\Column(name="player_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $playerId;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Myteam
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Myteam")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="myteam_id", referencedColumnName="myteam_id")
* })
*/
private $myteam;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Teams
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Teams")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="team_id", referencedColumnName="team_id")
* })
*/
private $team;
/**
* #var \VolleyScout\VolleyScoutBundle\Entity\Users
*
* #ORM\ManyToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Users")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* })
*/
private $user;
/**
* Set playerName
*
* #param string $playerName
* #return Players
*/
public function setPlayerName($playerName)
{
$this->playerName = $playerName;
return $this;
}
/**
* Get playerName
*
* #return string
*/
public function getPlayerName()
{
return $this->playerName;
}
/**
* Set playerLicensenumber
*
* #param string $playerLicensenumber
* #return Players
*/
public function setPlayerLicensenumber($playerLicensenumber)
{
$this->playerLicensenumber = $playerLicensenumber;
return $this;
}
/**
* Get playerLicensenumber
*
* #return string
*/
public function getPlayerLicensenumber()
{
return $this->playerLicensenumber;
}
/**
* Set playerPosition
*
* #param string $playerPosition
* #return Players
*/
public function setPlayerPosition($playerPosition)
{
$this->playerPosition = $playerPosition;
return $this;
}
/**
* Get playerPosition
*
* #return string
*/
public function getPlayerPosition()
{
return $this->playerPosition;
}
/**
* Set playerBirthyear
*
* #param \DateTime $playerBirthyear
* #return Players
*/
public function setPlayerBirthyear($playerBirthyear)
{
$this->playerBirthyear = $playerBirthyear;
return $this;
}
/**
* Get playerBirthyear
*
* #return \DateTime
*/
public function getPlayerBirthyear()
{
return $this->playerBirthyear;
}
/**
* Get playerId
*
* #return integer
*/
public function getPlayerId()
{
return $this->playerId;
}
/**
* Set myteam
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Myteam $myteam
* #return Players
*/
public function setMyteam(\VolleyScout\VolleyScoutBundle\Entity\Myteam $myteam = null)
{
$this->myteam = $myteam;
return $this;
}
/**
* Get myteam
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Myteam
*/
public function getMyteam()
{
return $this->myteam;
}
/**
* Set team
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Teams $team
* #return Players
*/
public function setTeam(\VolleyScout\VolleyScoutBundle\Entity\Teams $team = null)
{
$this->team = $team;
return $this;
}
/**
* Get team
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Teams
*/
public function getTeam()
{
return $this->team;
}
/**
* Set user
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Users $user
* #return Players
*/
public function setUser(\VolleyScout\VolleyScoutBundle\Entity\Users $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Users
*/
public function getUser()
{
return $this->user;
}
}
When I try add a player field I get this error:
Neither the property "player" nor one of the methods "getPlayer()", "isPlayer()", "hasPlayer()", "__get()" exist and have public access in class "VolleyScout\VolleyScoutBundle\Entity\Users".
UPDATE 2:
And I also have a FK in my players table 'team_id'. So when I create a user I would like to also select a team. So what I want is a list from all the teams in the database and set is as a choice field type in my Form. Do you know how I can place that in my formtype?
UPDATE 3:
I've added the following to my Users entity class:
private $player;
/**
* Get player
*
* #return \VolleyScout\VolleyScoutBundle\Entity\Players
*/
public function getPlayer() {
return $this->player;
}
/**
* Set player
*
* #param \VolleyScout\VolleyScoutBundle\Entity\Players $player
* #return Users
*/
public function setPlayer(\VolleyScout\VolleyScoutBundle\Entity\Players $player){
$this->player = $player;
}
In my formtype I've added:
->add('player')
Now in my form I want to do the following:
{{ form_label(registerForm.player.playerLicensenumber, label|default(),
Because in my Players entity class I have playerLicensenumber but I always get this error:
Method "playerLicensenumber" for object "Symfony\Component\Form\FormView" does not exist in VolleyScoutBundle:User:register.html.twig at line 57
UPDATE 4:
Is this a good solution:
Added this to my register form:
->add('player', new PlayerType())
And in my playertype I have the fields from player table.
You have to add a setter and a getter for your "player" field in your User entity.
public function getPlayer() {
return $this->player;
}
public function setPlayer(\Path\to\player\entity $player){
$this->player = $player;
}
For the team list in your form, you have to add an "entity" field type. Here are the docs for more info : http://symfony.com/doc/current/reference/forms/types/entity.html

Categories