Note that there are some explanatory texts on larger screens.

plurals
  1. POValidation error on ManyToMany form
    text
    copied!<p>I want to build a form to store some data. A "Tarea" could have many "Material" and a "Material" coul belong to one or more "Tarea". The "Material" entity has a image property, with picture upload.</p> <p>I can create a new "Material" with a picture with no problem. The problem becomes when I tried to create a new "Tarea", when I submit the form, I´m getting "The file could not be found" error.</p> <p>This is my Material entity with the file upload function:</p> <pre><code>/** * Gitek\HotelBundle\Entity\Material * * @ORM\Table() * @ORM\Entity(repositoryClass="Gitek\HotelBundle\Entity\MaterialRepository") */ class Material { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $nombre * * @ORM\Column(name="nombre", type="string", length=100) */ private $nombre; /** * @ORM\Column(type="string", nullable="true") * * @Assert\Image(maxSize = "500k") */ protected $imagen; /** * @var datetime $created_at * * @ORM\Column(name="created_at", type="datetime") */ private $created_at; /** * @var datetime $updated_at * * @ORM\Column(name="updated_at", type="datetime") */ private $updated_at; /** * @ORM\ManyToMany(targetEntity="Tarea", mappedBy="materiales") */ protected $tareas; public function __construct() { $this-&gt;created_at = new \DateTime(); $this-&gt;updated_at = new \DateTime(); } public function __toString() { return $this-&gt;getNombre(); } /** * Sube la foto de la incidencia copiándola en el directorio que se indica y * guardando en la entidad la ruta hasta la foto * * @param string $directorioDestino Ruta completa del directorio al que se sube la foto */ public function subirImagen($directorioDestino) { if (null === $this-&gt;imagen) { return; } $nombreArchivoImagen = uniqid('material-').'-1.'.$this-&gt;imagen-&gt;guessExtension(); $this-&gt;imagen-&gt;move($directorioDestino, $nombreArchivoImagen); $this-&gt;setImagen($nombreArchivoImagen); } </code></pre> <p>This is my Tarea entity:</p> <pre><code>/** * Gitek\HotelBundle\Entity\Tarea * * @ORM\Table() * @ORM\Entity(repositoryClass="Gitek\HotelBundle\Entity\TareaRepository") */ class Tarea { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $nombre * * @ORM\Column(name="nombre", type="string", length=100) */ private $nombre; /** * @var datetime $created_at * * @ORM\Column(name="created_at", type="datetime") */ private $created_at; /** * @var datetime $updated_at * * @ORM\Column(name="updated_at", type="datetime") */ private $updated_at; /** @ORM\ManyToOne(targetEntity="Gitek\HotelBundle\Entity\Tipotarea") */ protected $tipotarea; /** * @ORM\ManyToMany(targetEntity="Material", inversedBy="tareas") * @ORM\JoinTable(name="material_tarea", * joinColumns={@ORM\JoinColumn(name="tarea_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="material_id", referencedColumnName="id")} * ) */ protected $materiales; </code></pre> <p>And this my MaterialType form type:</p> <pre><code>&lt;?php namespace Gitek\BackendBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class MaterialType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder -&gt;add('nombre') -&gt;add('imagen') ; } public function getName() { return 'gitek_hotelbundle_materialtype'; } } </code></pre> <p>As I said, when I upload de form I get "The file could not be found" error. It´s seems like the validation fails.</p> <p>Any help or clue?</p> <p>UPDATE: If in my TareaController I comment the validation line it works correctly. Any clue?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload