APIPlatform (Symfony/REST) - "Error: Bad Request : Invalid IRI\"1\"" - rest

there is the situation :
I would like to send information to my REST API (working on Symfony), but when i tried to send this line, i got some errors that i don't understand, like : This one .
I really tried to resolve it alone, but nothing helped me on forums.
I think about an attribute than can't probably be set to editiion, or the reverse : an attribute which is not in edition and has to be.
This is what i want : be able to modify "dateCommande" (attribute for Purchase Date) , "statut" (used for see the statement of the purchase) and "idUsager" (used for put an id for a user); and finally be able to create automatically an id ("$id").
Thanks beforehand to help me ! ^^
Code of my class "Categorie.php" :
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Commande
*
* #ORM\Table(name="commande", indexes={#ORM\Index(name="IDX_6EEAA67DCF034CDB", columns={"id_usager_id"})})
* #ORM\Entity
* #ApiResource(normalizationContext={"groups"={"commande"},"enable_max_depth"=true},denormalizationContext={"groups"={"commandeecriture"},"enable_max_depth"=true})
*/
class Commande
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #Groups({"commande"})
* #NotNull(message="L'id ne peut être null")
*/
private $id;
/**
* #var \DateTime
*
* #ORM\Column(name="date_commande", type="date", nullable=false)
* #Groups({"commande","commandeecriture"})
* #NotBlank(message="Date non renseignée")
*/
private $dateCommande;
/**
* #var string
*
* #ORM\Column(name="statut", type="string", length=255, nullable=false)
* #Groups({"commande","commandeecriture"})
* #NotBlank(message="Statut non renseigné")
*/
private $statut;
/**
* #var User
*
* #ORM\ManyToOne(targetEntity="User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id_usager_id", referencedColumnName="id")
* })
* #Groups({"commande", "commandeecriture"})
* #NotNull(message="L'id ne peut être null")
*/
private $idUsager;
/**
* Constructor
*/
public function __construct()
{
$this->idArticle = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* #return int
*/
public function getId(): int
{
return $this->id;
}
/**
* #param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* #return \DateTime
*/
public function getDateCommande(): \DateTime
{
return $this->dateCommande;
}
/**
* #param \DateTime $dateCommande
*/
public function setDateCommande(\DateTime $dateCommande): void
{
$this->dateCommande = $dateCommande;
}
/**
* #return string
*/
public function getStatut(): string
{
return $this->statut;
}
/**
* #param string $statut
*/
public function setStatut(string $statut): void
{
$this->statut = $statut;
}
/**
* #return User
*/
public function getIdUsager(): User
{
return $this->idUsager;
}
/**
* #param User $idUsager
*/
public function setIdUsager(User $idUsager): void
{
$this->idUsager = $idUsager;
}
}

api-platform uses IRI instead of entity ids, try to replace idUsager="1" by idUsager="/usager/1". I'm guessing usager is the name of the related entity but if it's not then you just need to replace the actual name in the snippet in general it must be /related-entity-name/id

Related

Doctrine Table Inheritance - No identifier/primary key specified for Entity

In Doctrine 2/Symfony 3 with Postgres as the database I am trying to create a table with following fields:
**actions-reviews**
id
action_id
action_task_id
document_id
review_to
review_date
review_description
review_by
is_effective
The table is either linked to a doc_id which is foreign key for an entity called Document or action_task_id for entity called ActionTask. In order to achieve this I am using inheritance mapping via the use of discriminator. In skipper the entity relationship look like this:
As you can see both the ActionTask and ActionReview are sub-set of Action entity.
My issue is when create the entities and run php bin/console doctrine:schema:update --force I get the following error:
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity "AppBundle\Entity\ActionTask
Review". Every Entity must have an identifier/primary key.
Reading the forums I add #ORM/Id to ActionTaskReview entity and then it updates the DB without any errors. However when I look at the postgres table only the document_id field is there not the action_task_id field. What I am doing wrong as the document_id does not throw the same error when I exclude #ORM/Id?
My Doctrine entities look like:
ActionReview.php
/**
* #ORM\Entity
* #ORM\Table(name="actions_reviews")
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="owner", type="string")
* #ORM\DiscriminatorMap({"document":"AppBundle\Entity\DocumentActionReview","action_task":"AppBundle\Entity\ActionTaskReview"})
* #Discriminator(field = "owner", map = {"document": "AppBundle\Entity\DocumentActionReview", "action_task": "AppBundle\Entity\ActionTaskReview"})
*/
abstract class ActionReview
{
/**
* #ORM\Id
* #ORM\Column(type="guid")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
private $review_date;
/**
* #ORM\Column(type="text", nullable=true)
*/
private $review_description;
/**
* #ORM\Column(type="boolean", nullable=true)
*/
private $is_effective;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Action", inversedBy="action_review")
* #ORM\JoinColumn(name="action_id", referencedColumnName="id")
*/
private $action;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Employee")
* #ORM\JoinColumn(name="review_to", referencedColumnName="id")
*/
private $review_to;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Employee")
* #ORM\JoinColumn(name="review_by", referencedColumnName="id")
*/
private $review_by;
/**
* Get id
*
* #return guid
*/
public function getId()
{
return $this->id;
}
/**
* Set reviewDate
*
* #param \DateTime $reviewDate
*
* #return ActionReview
*/
public function setReviewDate($reviewDate)
{
$this->review_date = $reviewDate;
return $this;
}
/**
* Get reviewDate
*
* #return \DateTime
*/
public function getReviewDate()
{
return $this->review_date;
}
/**
* Set reviewDescription
*
* #param string $reviewDescription
*
* #return ActionReview
*/
public function setReviewDescription($reviewDescription)
{
$this->review_description = $reviewDescription;
return $this;
}
/**
* Get reviewDescription
*
* #return string
*/
public function getReviewDescription()
{
return $this->review_description;
}
/**
* Set isEffective
*
* #param boolean $isEffective
*
* #return ActionReview
*/
public function setIsEffective($isEffective)
{
$this->is_effective = $isEffective;
return $this;
}
/**
* Get isEffective
*
* #return boolean
*/
public function getIsEffective()
{
return $this->is_effective;
}
/**
* Set action
*
* #param \AppBundle\Entity\Action $action
*
* #return ActionReview
*/
public function setAction(\AppBundle\Entity\Action $action = null)
{
$this->action = $action;
return $this;
}
/**
* Get action
*
* #return \AppBundle\Entity\Action
*/
public function getAction()
{
return $this->action;
}
/**
* Set reviewTo
*
* #param \AppBundle\Entity\Employee $reviewTo
*
* #return ActionReview
*/
public function setReviewTo(\AppBundle\Entity\Employee $reviewTo = null)
{
$this->review_to = $reviewTo;
return $this;
}
/**
* Get reviewTo
*
* #return \AppBundle\Entity\Employee
*/
public function getReviewTo()
{
return $this->review_to;
}
/**
* Set reviewBy
*
* #param \AppBundle\Entity\Employee $reviewBy
*
* #return ActionReview
*/
public function setReviewBy(\AppBundle\Entity\Employee $reviewBy = null)
{
$this->review_by = $reviewBy;
return $this;
}
/**
* Get reviewBy
*
* #return \AppBundle\Entity\Employee
*/
public function getReviewBy()
{
return $this->review_by;
}
}
ActionTaskReview.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
/**
* ActionTaskReview
* #ORM\Entity
*/
class ActionTaskReview
{
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\ActionTask", inversedBy="action_review")
* #ORM\JoinColumn(name="action_task_id", referencedColumnName="id") \AppBundle\Entity\ActionTask
*/
private $action_task;
/**
* Set actionTask
*
* #param \AppBundle\Entity\ActionTask $actionTask
*
* #return ActionTaskReview
*/
public function setActionTask(\AppBundle\Entity\ActionTask $actionTask = null)
{
$this->action_task = $actionTask;
return $this;
}
/**
* Get actionTask
*
* #return \AppBundle\Entity\ActionTask
*/
public function getActionTask()
{
return $this->action_task;
}
}
DocumentActionReview.php
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="documents_actions_reviews")
*/
class DocumentActionReview extends \AppBundle\Entity\ActionReview
{
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Document", inversedBy="action_review")
* #ORM\JoinColumn(name="document_id", referencedColumnName="id")
*/
private $document;
/**
* Set document
*
* #param \AppBundle\Entity\Document $document
*
* #return DocumentActionReview
*/
public function setDocument(\AppBundle\Entity\Document $document = null)
{
$this->document = $document;
return $this;
}
/**
* Get document
*
* #return \AppBundle\Entity\Document
*/
public function getDocument()
{
return $this->document;
}
}
First of all, your ActionTaskReview should extend ActionReview:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
/**
* ActionTaskReview
* #ORM\Entity
*/
class ActionTaskReview extends ActionReview
{
...
}
Than I am not sure what you want to achieve, as you are using Single Table Inheritance but are setting the #ORM\Table(name="documents_actions_reviews") annotation on the DocumentActionReview class. Either switch to Class Table Inheritance if you need own tables for your inherited entities or remove the annotation.
Every entity class must have an identifier/primary key. You can select the field that serves as the identifier with the #Id annotation.
`/**
* #ORM\Column(type="integer")
* #ORM\Id
* #GeneratedValue
*/
private $id;`

The target-entity cannot be found

I know this question has already been asked more than once, but I still can't figure what goes wrong.
I'm currently trying to learn Symfony2 (using version 2.7.4), and I'm getting the following error when I'm trying to reach a page that's supposed to have an image in it :
The target-entity Entity\Image cannot be found in 'OC\PlatformBundle\Entity\Advert#Image'.
Here is my code:
**advert.php**
<?php
namespace OC\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity(repositoryClass="OC\PlatformBundle\Entity\AdvertRepository")
*/
class Advert
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="published", type="boolean")
*/
private $published = true;
/**
* #ORM\OneToOne(targetEntity="Entity\Image", cascade={"persist"})
*/
private $image;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="author", type="string", length=255)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* Set image
*
* #param \OC\PlatformBundle\Entity\Image $image
*
* #return Advert
*/
public function setImage(\OC\PlatformBundle\Entity\Image $image = null)
{
$this->image = $image;
return $this;
}
/**
* Get Image
*
* #return \OC\PlatformBundle\Entity\Image
*/
public function getImage()
{
return $this->Image;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function __construct()
{
// Par défaut, la date de l'annonce est la date d'aujourd'hui
$this->date = new \Datetime();
}
/**
* Set date
*
* #param \DateTime $date
*
* #return Advert
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set title
*
* #param string $title
*
* #return Advert
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set author
*
* #param string $author
*
* #return Advert
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set content
*
* #param string $content
*
* #return Advert
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set published
*
* #param boolean $published
*
* #return Advert
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* Get published
*
* #return boolean
*/
public function getPublished()
{
return $this->published;
}
}
file Image :
<?php
// src/OC/PlatformBundle/Entity/Image
namespace OC\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
*/
class Image
{
/**
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="url", type="string", length=255)
*/
private $url;
/**
* #ORM\Column(name="alt", type="string", length=255)
*/
private $alt;
}
I understood that this problem mainly comes from a typo in the call of the entity, but I triple-checked everything, and it seems alright to me... Is there something I didn't see ?
Thank you in advance
You should fix your annotation:
/**
* #ORM\OneToOne(targetEntity="OC\PlatformBundle\Entity\Image", cascade={"persist"})
*/
private $image;

Relationship between two entities

I have a trouble and I need your assistance. Now I create two entities :
Partner
PartnerMedia
Partner entity contains all information about my partners and the other entity, have relationship with Partner and Sonata Media Entity.
There is what contains my partner entity :
<?php
namespace AppBundle\Entity;
use AppBundle\Entity\CMS\Block;
use AppBundle\Entity\SuperClass\SortableTranslatableEntity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Sonata\MediaBundle\Model\Media;
use Doctrine\Common\Collections\ArrayCollection;
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
/**
* Partner.
*
* #ORM\Table("partner")
* #ORM\Entity
*/
class Partner extends SortableTranslatableEntity implements TranslatableInterface
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="libelle", type="string", length=60)
* #Gedmo\Translatable
*/
private $libelle;
/**
* #var string
*
* #ORM\Column(name="mea", type="boolean")
*/
private $mea;
/**
* #ORM\OneToMany(targetEntity="\AppBundle\Entity\Media\PartnerMedia", mappedBy="partner", cascade={"persist"}, orphanRemoval=true)
* #ORM\OrderBy({"position" = "ASC"})
*/
private $medias;
/**
* #ORM\Column(type="string", name="url", nullable=true)
* #Gedmo\Translatable
*/
private $url;
/**
* #ORM\ManyToOne(targetEntity="\AppBundle\Entity\CMS\Block", inversedBy="block")
*/
private $block;
public function __construct()
{
$this->medias = new ArrayCollection();
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getContextName()
{
return 'partner';
}
public function __toString()
{
return $this->getId() ? (string) $this->getLibelle() : '-';
}
public function firstPhoto()
{
if ($this->getMedias() && $this->getMedias()->count()) {
return $this->getMedias()->first()->getMedia();
}
}
public function getId()
{
return $this->id;
}
public function getLibelle()
{
return $this->libelle;
}
/**
* Add medias.
*
* #param PartnerMedia $media
*
* #return PartnerMedia
*/
public function addMedias(PartnerMedia $media)
{
$media->setPartner($this);
$this->medias[] = $media;
return $this;
}
/**
* Remove medias.
*
* #param PartnerMedia $media
*/
public function removeMedia(PartnerMedia $media)
{
$this->medias->removeElement($media);
}
public function getMedias()
{
return $this->medias;
}
public function getUrl()
{
return $this->url;
}
/**
* Get page.
*
* #return \AppBundle\Entity\CMS\Block
*/
public function getBlock()
{
return $this->block;
}
public function setId($id)
{
$this->id = $id;
}
public function setLibelle($libelle)
{
$this->libelle = $libelle;
}
public function setUrl($url)
{
$this->url = $url;
}
/**
* Set page.
*
* #param \AppBundle\Entity\CMS\Block $block
* #return Partner
*/
public function setBlock(Block $block = null)
{
$this->block = $block;
return $this;
}
/**
* Set mea
*
* #param boolean $mea
* #return Partner
*/
public function setMea($mea)
{
$this->mea = $mea;
return $this;
}
/**
* Get mea
*
* #return boolean
*/
public function getMea()
{
return $this->mea;
}
/**
* #param mixed $medias
*/
public function setMedias($medias)
{
$this->medias = $medias;
}
}
and what contains PartnerMedia entity :
<?php
/**
* PartnerMedia
*
* #ORM\Table()
* #ORM\Entity
*/
class PartnerMedia extends SortableEntity
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Media")
*/
private $medias;
/**
* #ORM\ManyToOne(targetEntity="\AppBundle\Entity\Partner", inversedBy="partner")
*
* #Gedmo\SortableGroup
*/
private $partner;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set medias
*
* #param Media $medias
* #return PartnerMedia
*/
public function setMedias(Media $medias = null)
{
$this->medias = $medias;
return $this;
}
/**
* Get medias
*
* #return Media
*/
public function getMedias()
{
return $this->medias;
}
/**
* Set Partner
*
* #param Partner $partner
* #return PartnerMedia
*/
public function setPartner(Partner $partner = null)
{
$this->partner = $partner;
return $this;
}
/**
* Get Partner
*
* #return Partner
*/
public function getPartner()
{
return $this->partner;
}
public function getContextName()
{
return 'partner_media';
}
public function __construct()
{
$this->medias = new ArrayCollection();
}
}
Now when I tried to create a new partner, I receive that exception :
The current field medias is not linked to an admin. Please create one for the target entity : AppBundle\Entity\Media\PartnerMedia
I need your assistance please and thanks
The error message you describe sounds more like a Sonata Admin error.
One of the things about sonata admin is that when you are creating links between entities, you need to have admin classes built for both entity classes.
More than likely, you're trying to test your code before completely implementing the admins necessary to do so.

Fill my form with the data that I pick up from a table - Symfony2

My problem is this : I have an entity that contains user data , such as:
age
name
surname
address
phone
...
My goal is to make a form where using a query can bring all this data and fill my form with the data , so that the user can modify it if you ever change the cell for example, or changing the direction of his house.
The company and I have made the entity​​ and the form, and consulting the table will do. My problem is how to fill the form fields with the data that I get from the table.
My entity (DatosEntity):
<?php
namespace Proyecto\LavocBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Datos
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Proyecto\LavocBundle\Entity\DatosRepository")
*/
class Datos
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="empresa", type="string", length=50)
*/
private $empresa;
/**
* #var integer
*
* #ORM\Column(name="cuit", type="integer")
*/
private $cuit;
/**
* #var string
*
* #ORM\Column(name="localidad", type="string", length=50)
*/
private $localidad;
/**
* #var string
*
* #ORM\Column(name="calle", type="string", length=40)
*/
private $calle;
/**
* #var integer
*
* #ORM\Column(name="altura", type="integer")
*/
private $altura;
/**
* #var integer
*
* #ORM\Column(name="areaTel", type="integer")
*/
private $areaTel;
/**
* #var integer
*
* #ORM\Column(name="telefono", type="integer")
*/
private $telefono;
/**
* #var integer
*
* #ORM\Column(name="areaCel", type="integer")
*/
private $areaCel;
/**
* #var integer
*
* #ORM\Column(name="celular", type="integer")
*/
private $celular;
/**
* #ORM\OneToOne(targetEntity="User", inversedBy="datos")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $personales;
/**
* #var string
*
* #ORM\Column(name="email", type="string")
*/
private $email;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set empresa
*
* #param string $empresa
* #return Datos
*/
public function setEmpresa($empresa)
{
$this->empresa = $empresa;
return $this;
}
/**
* Get empresa
*
* #return string
*/
public function getEmpresa()
{
return $this->empresa;
}
/**
* Set cuit
*
* #param integer $cuit
* #return Datos
*/
public function setCuit($cuit)
{
$this->cuit = $cuit;
return $this;
}
/**
* Get cuit
*
* #return integer
*/
public function getCuit()
{
return $this->cuit;
}
/**
* Set localidad
*
* #param string $localidad
* #return Datos
*/
public function setLocalidad($localidad)
{
$this->localidad = $localidad;
return $this;
}
/**
* Get localidad
*
* #return string
*/
public function getLocalidad()
{
return $this->localidad;
}
/**
* Set calle
*
* #param string $calle
* #return Datos
*/
public function setCalle($calle)
{
$this->calle = $calle;
return $this;
}
/**
* Get calle
*
* #return string
*/
public function getCalle()
{
return $this->calle;
}
/**
* Set altura
*
* #param integer $altura
* #return Datos
*/
public function setAltura($altura)
{
$this->altura = $altura;
return $this;
}
/**
* Get altura
*
* #return integer
*/
public function getAltura()
{
return $this->altura;
}
/**
* Set telefono
*
* #param integer $telefono
* #return Datos
*/
public function setTelefono($telefono)
{
$this->telefono = $telefono;
return $this;
}
/**
* Get telefono
*
* #return integer
*/
public function getTelefono()
{
return $this->telefono;
}
/**
* Set area
*
* #param integer $area
* #return Datos
*/
public function setAreaTel($areaTel)
{
$this->areaTel = $areaTel;
return $this;
}
/**
* Get area
*
* #return integer
*/
public function getAreaTel()
{
return $this->areaTel;
}
/**
* Set celular
*
* #param integer $celular
* #return Datos
*/
public function setCelular($celular)
{
$this->celular = $celular;
return $this;
}
/**
* Get celular
*
* #return integer
*/
public function getCelular()
{
return $this->celular;
}
/**
* Set areaCel
*
* #param integer $areaCel
* #return Datos
*/
public function setAreaCel($areaCel)
{
$this->areaCel = $areaCel;
return $this;
}
/**
* Get areaCel
*
* #return integer
*/
public function getAreaCel()
{
return $this->areaCel;
}
/**
* Set email
*
* #param integer $email
* #return Datos
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return integer
*/
public function getEmail()
{
return $this->email;
}
/**
* Set personales
*
* #param string $personales
* #return Datos
*/
public function setPersonales($personales)
{
$this->personales = $personales;
return $this;
}
/**
* Get personales
*
* #return string
*/
public function getPersonales()
{
return $this->personales;
}
}
My DatosType:
<?php
namespace Proyecto\LavocBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class DatosType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('empresa');
$builder->add('cuit');
$builder->add('localidad');
$builder->add('calle');
$builder->add('altura');
$builder->add('areaTel');
$builder->add('telefono');
$builder->add('areaCel');
$builder->add('celular');
}
public function getName()
{
return 'datos_form';
}
}
The consultation on the controller but did not know how to do it. Now , do not like taking the data I receive and dump them in the form.
Thank you very much and sorry for the trouble
I think what you want to do can be done by following these steps :
Start by collecting your User data in a variable we will call $user
Then, give this $userto be hydrated by your form, like this :
$form = $this->createForm(new UserType(), $user);
Treat your form like you would normaly do. The values found in the entity should be automaticaly filled in your form.
Hope this helps.
Your action could be something like this:
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('LavocBundle:User')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createForm(new UserType(), $entity);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
);
}

A2lix TranslationFormBundle - Gedmo Doctrine Extension - Unwanted form fields

I am trying to build forms for translatable entities but i get 4 form fields that i don't want.
It seems these fields are coming from the Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation but i wonder what i need to do with these fields ?
Is it normal that they are appearing in the translation form ?
If someone have usefull examples that would be great.
It's a Symfony2 project.
Doctrine extensions are installed with stof:
https://github.com/stof/StofDoctrineExtensionsBundle/
Aj2lix TranslationFormBundle:
https://github.com/a2lix/TranslationFormBundle
Please find below the following files:
Page.php (this is the main entity)
PageTranslation.php (the translation entity)
Page.php
<?php
namespace Syms\PageBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Page
*
* #Gedmo\Tree(type="nested")
* #ORM\Table(name="syms_page")
* #ORM\Entity(repositoryClass="Syms\PageBundle\Entity\PageRepository")
*/
class Page
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var boolean
*
* #ORM\Column(name="is_active", type="boolean", nullable=false, options={"default":0})
*/
private $isActive;
/**
* #var boolean
*
* #ORM\Column(name="is_homepage", type="boolean", nullable=false, options={"default":0})
*/
private $isHomepage;
/**
* #var \DateTime
*
* #Gedmo\Timestampable(on="create")
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
protected $translations;
/**
* #Gedmo\TreeLeft
* #ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* #Gedmo\TreeRight
* #ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeLevel
* #ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="Page", inversedBy="children")
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #Gedmo\TreeRoot
* #ORM\Column(name="root", type="integer", nullable=true)
*/
private $root;
/**
* #ORM\OneToMany(targetEntity="Page", mappedBy="parent")
* #ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
/**
* Required for Translatable behaviour
* #Gedmo\Locale
*/
protected $locale;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
$this->translations = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set isActive
*
* #param boolean $isActive
* #return Page
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isHomepage
*
* #param boolean $isHomepage
* #return Page
*/
public function setIsHomepage($isHomepage)
{
$this->isHomepage = $isHomepage;
return $this;
}
/**
* Get isHomepage
*
* #return boolean
*/
public function getIsHomepage()
{
return $this->isHomepage;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
* #return Page
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
public function setParent(Page $parent)
{
$this->parent = $parent;
}
public function getParent()
{
return $this->parent;
}
/**
* Set lft
*
* #param integer $lft
* #return Page
*/
public function setLft($lft)
{
$this->lft = $lft;
return $this;
}
/**
* Get lft
*
* #return integer
*/
public function getLft()
{
return $this->lft;
}
/**
* Set rgt
*
* #param integer $rgt
* #return Page
*/
public function setRgt($rgt)
{
$this->rgt = $rgt;
return $this;
}
/**
* Get rgt
*
* #return integer
*/
public function getRgt()
{
return $this->rgt;
}
/**
* Set lvl
*
* #param integer $lvl
* #return Page
*/
public function setLvl($lvl)
{
$this->lvl = $lvl;
return $this;
}
/**
* Get lvl
*
* #return integer
*/
public function getLvl()
{
return $this->lvl;
}
/**
* Set root
*
* #param integer $root
* #return Page
*/
public function setRoot($root)
{
$this->root = $root;
return $this;
}
/**
* Get root
*
* #return integer
*/
public function getRoot()
{
return $this->root;
}
/**
* Add children
*
* #param \Syms\PageBundle\Entity\Page $children
* #return Page
*/
public function addChild(Page $children)
{
$this->children[] = $children;
return $this;
}
/**
* Remove children
*
* #param \Syms\PageBundle\Entity\Page $children
*/
public function removeChild(Page $children)
{
$this->children->removeElement($children);
}
/**
* Get children
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(PageTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
}
public function removeTranslation(PageTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
$this->translations = $translations;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}
PageTranslation.php
<?php
namespace Syms\PageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #ORM\Table(name="ext_translations_page", indexes={
* #ORM\Index(name="page_translation_idx", columns={"locale", "object_class", "field", "foreign_key"})
* })
* #ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class PageTranslation extends AbstractTranslation
{
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="meta_title", type="string", length=255)
*/
private $metaTitle;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="meta_keywords", type="text", nullable=true)
*/
private $metaKeywords;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="meta_description", type="text", nullable=true)
*/
private $metaDescription;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="url_key", type="string", length=255)
*/
private $urlKey;
/**
* Set title
*
* #param string $title
* #return PageTranslation
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set metaTitle
*
* #param string $metaTitle
* #return PageTranslation
*/
public function setMetaTitle($metaTitle)
{
$this->metaTitle = $metaTitle;
return $this;
}
/**
* Get metaTitle
*
* #return string
*/
public function getMetaTitle()
{
return $this->metaTitle;
}
/**
* Set metaKeywords
*
* #param string $metaKeywords
* #return PageTranslation
*/
public function setMetaKeywords($metaKeywords)
{
$this->metaKeywords = $metaKeywords;
return $this;
}
/**
* Get metaKeywords
*
* #return string
*/
public function getMetaKeywords()
{
return $this->metaKeywords;
}
/**
* Set metaDescription
*
* #param string $metaDescription
* #return PageTranslation
*/
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
return $this;
}
/**
* Get metaDescription
*
* #return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* Set urlKey
*
* #param string $urlKey
* #return PageTranslation
*/
public function setUrlKey($urlKey)
{
$this->urlKey = $urlKey;
return $this;
}
/**
* Get urlKey
*
* #return string
*/
public function getUrlKey()
{
return $this->urlKey;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
I've finally succeeded in displaying the correct fields.
You have to downgrade the a2lix form bundle to version 1.4.
In fact, in version 2.0, the field type "a2lix_translations_gedmo" is no more available, which is actually what you need when using Gedmo Translatable.
There's nothing to change on your entity side. Just follow the doc for the config.yml, and use "a2lix_translations_gedmo" in your PageType :
$builder->add('translations', 'a2lix_translations_gedmo', array(
'translatable_class' => "Syms\PageBundle\Entity\Page"
);
I've also red somewhere that you can keep using version 2.0 of a2lix Form Bundle, but in this case you have to use a specific branch of doctrine extensions (wip-v2.4.0).
Regards,