Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/07/2014, 10:03
sxwark
 
Fecha de Ingreso: agosto-2013
Ubicación: Oyón/Alava
Mensajes: 23
Antigüedad: 10 años, 9 meses
Puntos: 0
Respuesta: Obtener datos de Base de datos en controlador symfony2

Buenas siento la tardanza.

Las entidades relacionadas en el error son las siguientes.


Entidad Carrito:
Código PHP:
<?php

namespace wolfrcfrontenBundleEntity
;

use 
DoctrineORMMapping as ORM;
use 
DoctrineCommonCollectionsArrayCollection;

/**
 * carrito
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="wolfrc\frontenBundle\Entity\carritoRepository")
 */
class carrito
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

    
/**
     * @var string
     *
     * @ORM\Column(name="idcliente", type="string", length=255, nullable=true)
     */
    
private $idcliente;

    
/**
     * @var string
     *
     * @ORM\Column(name="session", type="text")
     */
    
private $session;
    
    
/**
     *
     * @ORM\OneToMany(targetEntity="productoCarro", mappedBy="carrito")
     */
    
protected $productoCarro;
    
    
    public function 
__construct() {
        
$this->productoCarro = new ArrayCollection();
    }
    


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

    
/**
     * Set idcliente
     *
     * @param string $idcliente
     * @return carrito
     */
    
public function setIdcliente($idcliente)
    {
        
$this->idcliente $idcliente;

        return 
$this;
    }

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

    
/**
     * Set session
     *
     * @param string $session
     * @return carrito
     */
    
public function setSession($session)
    {
        
$this->session $session;

        return 
$this;
    }

    
/**
     * Get session
     *
     * @return string 
     */
    
public function getSession()
    {
        return 
$this->session;
    }
}
Entidad ProductoCarro:
Código PHP:
<?php

namespace wolfrcfrontenBundleEntity
;

use 
DoctrineORMMapping as ORM;

/**
 * productoCarro
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="wolfrc\frontenBundle\Entity\productoCarroRepository")
 */
class productoCarro
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

    
/**
     * @var string
     *
     * @ORM\Column(name="producto", type="string", length=255)
     */
    
private $producto;

    
/**
     * @ORM\ManyToOne(targetEntity="carrito", inversedBy="productoCarro")
     * @ORM\JoinColumn(name="carrito_id", referencedColumnName="id")
     */
    
protected $carrito;

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

    
/**
     * Set producto
     *
     * @param string $producto
     * @return productoCarro
     */
    
public function setProducto($producto)
    {
        
$this->producto $producto;

        return 
$this;
    }

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

Y el error que me devuelve symfony es el siguiente.
Código HTML:
 FatalErrorException: Error: Call to a member function getId() on a non-object in /home/endika/www/wolfrc/src/wolfrc/frontenBundle/Controller/carritoController.php line 35
La linea en cuestion es la siguiente.
Código PHP:
$carro $em->getRepository('frontenBundle:carrito')->findCarrito($session->getId());
        
        
$this->addProductoCarro($carro->getId(), $id); 

Ahora bien lo que yo intento hacer es lo siguiente, por medio de un link cuando se pincha se accede al controlador que mira si tenemos un carro sino lo creamos y le asignamos la sesión del usuario.

El problema viene cuando quiero asociar los el productoCarro al carrito correspondiente.

Espero haberme explicado con claridad y gracias otra vez.