Foros del Web » Programando para Internet » PHP » Symfony »

[SOLUCIONADO] Neither the property "items" nor one of the methods "addItem()"/"removeItem()"...

Estas en el tema de Neither the property "items" nor one of the methods "addItem()"/"removeItem()"... en el foro de Symfony en Foros del Web. Tengo este formulario: Código PHP: public function  buildForm ( FormBuilderInterface $builder , array  $options ) {      $builder          -> add ( 'dateStart' , 'genemu_jquerydate' ,array( 'required'   =>  ...
  #1 (permalink)  
Antiguo 01/06/2015, 08:24
Avatar de bNd170  
Fecha de Ingreso: agosto-2009
Ubicación: $this->setLocation('Valencia', 'Spain');
Mensajes: 365
Antigüedad: 14 años, 7 meses
Puntos: 13
Neither the property "items" nor one of the methods "addItem()"/"removeItem()"...

Tengo este formulario:

Código PHP:
public function buildForm(FormBuilderInterface $builder, array $options)
{
    
$builder
        
->add('dateStart','genemu_jquerydate',array('required'  => true'widget' => 'single_text'))
        ->
add('dateFinish','genemu_jquerydate',array('required'  => true'widget' => 'single_text'))
        ->
add('image''genemu_jqueryimage', array(
        
'configs' => array(
            
'auto' => true,
            
'multiple' => false
        
)))
        ->
add('items''genemu_jqueryselect2_entity', array(
            
'class' => 'Acme\sampleBundle\Entity\Item',
            
'property' => 'name',
            
'configs' => array(
                
'multiple' => true
                
)
            )
        )
        ;

Se genera correctamente pero al ir a guardar me ocurre esto:

Código:
Neither the property "items" nor one of the methods "addItem()"/"removeItem()", "setItems()", "items()", "__set()" or "__call()" exist and have public access in class "Acme\sampleBundle\Entity\Draw".
Mi clase de Draw es esta:

Código PHP:
<?php

namespace AcmesampleBundleEntity
;

use 
DoctrineORMMapping as ORM;
use 
SymfonyComponentValidatorConstraints as Assert;

/**
 * Draw
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="acme\sampleBundle\Entity\DrawRepository")
 */
class Draw
{    
    public function 
__construct() {
        
$this->items = new DoctrineCommonCollectionsArrayCollection();
    }

    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;


    
/**
     * @ORM\ManyToMany(targetEntity="Acme\sampleBundle\Entity\Item")
     * @ORM\JoinTable(name="draw_item",
     *      joinColumns={@ORM\JoinColumn(name="draw_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="item_id", referencedColumnName="id")}
     *      )
     * @Assert\NotBlank()
     **/
    
private $items;

    
/**
     * @ORM\ManyToOne(targetEntity="Acme\sampleBundle\Entity\User", inversedBy="drawsWins")
     * @ORM\JoinColumn(name="user_winner_id", referencedColumnName="id")
     **/
    
private $winner;

    
/**
     * @var \DateTime
     *
     * @ORM\Column(name="dateStart", type="datetime")
     * @Assert\NotBlank()
     */
    
private $dateStart;

    
/**
     * @var \DateTime
     *
     * @ORM\Column(name="dateFinish", type="datetime")
     * @Assert\NotBlank()
     */
    
private $dateFinish;

    
/**
     * @var string
     *
     * @ORM\Column(name="image", type="text")
     **/
    
private $image;

    
/**
     * @var string
     *
     * @ORM\Column(name="description", type="text")
     */
    
private $description '';

    
/**
     * @var string
     *
     * @ORM\Column(name="state", type="string", length=1)
     */
    
private $state 0;

    
/**
     * @ORM\ManyToOne(targetEntity="Acme\sampleBundle\Entity\User")
     * @ORM\JoinColumn(name="user_maker_id", referencedColumnName="id")
     **/
    
private $maker;


    
/**
     * Get id
     *
     * @return integer
     */
    
public function getId()
    {
        return 
$this->id;
    }

    
/**
     * Set dateStart
     *
     * @param \DateTime $dateStart
     *
     * @return Draw
     */
    
public function setDateStart($dateStart)
    {
        
$this->dateStart $dateStart;

        return 
$this;
    }

    
/**
     * Get dateStart
     *
     * @return \DateTime
     */
    
public function getDateStart()
    {
        return 
$this->dateStart;
    }

    
/**
     * Set dateFinish
     *
     * @param \DateTime $dateFinish
     *
     * @return Draw
     */
    
public function setDateFinish($dateFinish)
    {
        
$this->dateFinish $dateFinish;

        return 
$this;
    }

    
/**
     * Get dateFinish
     *
     * @return \DateTime
     */
    
public function getDateFinish()
    {
        return 
$this->dateFinish;
    }

    
/**
     * Set image
     *
     * @param string $image
     *
     * @return Draw
     */
    
public function setImage($image)
    {
        
$this->image $image;

        return 
$this;
    }

    
/**
     * Get image
     *
     * @return string
     */
    
public function getImage()
    {
        return 
$this->image;
    }

    
/**
     * Set description
     *
     * @param string $description
     *
     * @return Draw
     */
    
public function setDescription($description)
    {
        
$this->description $description;

        return 
$this;
    }

    
/**
     * Get description
     *
     * @return string
     */
    
public function getDescription()
    {
        return 
$this->description;
    }

    
/**
     * Set state
     *
     * @param string $state
     *
     * @return Draw
     */
    
public function setState($state)
    {
        
$this->state $state;

        return 
$this;
    }

    
/**
     * Get state
     *
     * @return string
     */
    
public function getState()
    {
        return 
$this->state;
    }

    
/**
     * Add item
     *
     * @param \Acme\sampleBundle\Entity\Item $item
     *
     * @return Draw
     */
    
public function addItem(AcmesampleBundleEntityItem $item)
    {
        
$this->items[] = $item;

        return 
$this;
    }

    
/**
     * Remove item
     *
     * @param \Acme\sampleBundle\Entity\Item $item
     */
    
public function removeItem(AcmesampleBundleEntityItem $item)
    {
        
$this->items->removeElement($item);
    }

    
/**
     * Get items
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    
public function getItems()
    {
        return 
$this->items;
    }

    
/**
     * Set winner
     *
     * @param \Acme\sampleBundle\Entity\User $winner
     *
     * @return Draw
     */
    
public function setWinner(AcmesampleBundleEntityUser $winner null)
    {
        
$this->winner $winner;

        return 
$this;
    }

    
/**
     * Get winner
     *
     * @return \Acme\sampleBundle\Entity\User
     */
    
public function getWinner()
    {
        return 
$this->winner;
    }

    
/**
     * Set maker
     *
     * @param \Acme\sampleBundle\Entity\User $maker
     *
     * @return Draw
     */
    
public function setMaker(AcmesampleBundleEntityUser $maker null)
    {
        
$this->maker $maker;

        return 
$this;
    }

    
/**
     * Get maker
     *
     * @return \Acme\sampleBundle\Entity\User
     */
    
public function getMaker()
    {
        return 
$this->maker;
    }
}
He revisado todo mil veces y no comprendo porque falla.
  #2 (permalink)  
Antiguo 01/06/2015, 11:56
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 9 meses
Puntos: 379
Respuesta: Neither the property "items" nor one of the methods "addItem()"/"removeIte

No utilizo ese bundle pero el error que te aparece, es común cuando tienes relaciones n:m(como en este caso) y no le indicas el multiple al tipo entity. Lo raro es que en el ejemplo lo estén indicando dentro del config. Revisa si extiende o implementa un nuevo tipo o prueba colocando el multiple fuera del config
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #3 (permalink)  
Antiguo 01/06/2015, 12:53
Avatar de bNd170  
Fecha de Ingreso: agosto-2009
Ubicación: $this->setLocation('Valencia', 'Spain');
Mensajes: 365
Antigüedad: 14 años, 7 meses
Puntos: 13
Respuesta: Neither the property "items" nor one of the methods "addItem()"/"removeIte

La relacion de M:M manytomany con una tabla mediadora con las ID de los registros para relacionarlos.

El caso es que estoy tratando de usar Select2 para mi web ya que me parece un plugin de jquery muy bueno e intuitivo para el usuario y me instalé ese bundle que no es más que un compendio de distintos tipos de campo para Doctrine y Symfony2.

Anteriormente el campo se llamaba item, pero al darme cuenta que iba a necesitar que la relación fuese de muchos a muchos lo cambié y siguiendo las buenas prácticas de symfony, pluraricé la propiedad para no salirme de los estándares de Symfony2.

Cual es mi sorpresa que cuando voy a usarla me sale ese error.

No extiende a nada el bundle, sencillamente modifica la plantilla del campo de Symfony2 y le da otra usabilidad al campo.

He probado usando el FieldType entity nativo de Symfony2 y el error sigue siendo el mismo con lo cual es algo de la entidad propia. He ejecutado el doctrine:generate:entities y tampoco.

Se me acaban las ideas para determinar que está ocurriendo, todo lo que he visto por internet ha fallado. He probado incluso mirando el log y limpiando la caché y nada.

EDIT

Finalmente tenias razón, al decirme la causa más común me has encendido la bombilla. El multiple => true estaba, pero era una propiedad del bundle, no del propio symfony2, con lo cual no funcionaba. He agregado el multiple y ya funciona.

Mil gracias, llavaba toda la jornada con esto.

Última edición por bNd170; 01/06/2015 a las 13:06

Etiquetas: items
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:03.