'Necesito Ayuda' - - Catchable Fatal Error: Argument 1 passed

1,284 views
Skip to first unread message

jvjsoft

unread,
May 6, 2012, 9:06:44 PM5/6/12
to symfony-es
buen dia....

Catchable Fatal Error: Argument 1 passed to Inventario\UbicacionBundle
\Entity\Ubicacion::setArea() must be an instance of Inventario
\AreaBundle\Entity\Area, null given, called in E:\inventario\src
\Inventario\RegistroBundle\Controller\RegistroController.php on line
79 and defined in E:\inventario\src\Inventario\UbicacionBundle\Entity
\Ubicacion.php line 119

estoy tratando de guardar asi

....inventario/registrobundle/registro

use Inventario\UbicacionBundle\Entity\Ubicacion;

...

public function createAction($bien_id) {
$bien = $this->getBien($bien_id);
$entity = new Registro();
$entity->setBien($bien);
$request = $this->getRequest();

$form = $this->createForm(new RegistroType(), $entity);
$form->bindRequest($request);



if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();

$this->guardaUsuario($request->request->get('area'),
$request->request->get('bien'),$request->request->get('estado'));



return $this->redirect($this->generateUrl('bien'));
}

return $this->render('RegistroBundle:Registro:new.html.twig',
array(
'entity' => $entity,
'form' => $form->createView()
));
}

public function guardaUsuario($area=1, $bien=1, $estado=1)
{
$ubicacion= new Ubicacion();
$ubicacion->setArea($area);
$ubicacion->setBien($bien);
$ubicacion->setEstado($estado);
$ubicacion->setFechaRegistro(new \DateTime('today'));

$em_ubi= $this->getDoctrine()->getEntityManager();
$em_ubi->persist($ubicacion);
$em_ubi->persist($ubicacion->setArea());
$em_ubi->persist($ubicacion->setBien());
$em_ubi->persist($ubicacion->setEstado());
$em_ubi->flush();
}
....

donde area, bien y estado tiene relacion muchos a uno... desde
ubicacion

* @ORM\ManyToOne(targetEntity="Inventario\BienBundle\Entity
\Bien", inversedBy="ubicaciones")
* @ORM\JoinColumn(name="bien_id", referencedColumnName="id")
*/
protected $bien;

/**
* @ORM\ManyToOne(targetEntity="Inventario\EstadoBundle\Entity
\Estado", inversedBy="ubicaciones")
* @ORM\JoinColumn(name="estado_id", referencedColumnName="id")
*/
private $estado;

/**
* @ORM\ManyToOne(targetEntity="Inventario\AreaBundle\Entity
\Area", inversedBy="ubicaciones")
* @ORM\JoinColumn(name="area_id", referencedColumnName="id")
*/
private $area;



ayuda!!!!!!!!!!

Fabricio Salinas

unread,
May 7, 2012, 12:54:27 AM5/7/12
to symfo...@googlegroups.com
Hola,
Lo que te esta indicando es que el argumento que le estas pasando a setArea() no es del tipo esperado.

Como tienes definido el set y que le estas pasando al llamarlo?

Saludos.

Enviado a través de BlackBerry
--
Has recibido este mensaje porque estás suscrito al grupo "symfony-es" de Google Groups.
Para publicar en este grupo, envía un email a symfo...@googlegroups.com
Para darte de baja, envía un email a symfony-es+...@googlegroups.com
El resto de opciones puedes encontrarlas en http://groups.google.com/group/symfony-es?hl=es

JavierVilcapaza

unread,
May 7, 2012, 1:00:13 AM5/7/12
to symfo...@googlegroups.com, fabricio...@gmail.com

   /**
     * Set bien
     *
     * @param Inventario\BienBundle\Entity\Bien $bien
     */
    public function setBien(\Inventario\BienBundle\Entity\Bien $bien)
    {
        $this->bien = $bien;
    }

    /**
     * Get bien
     *
     * @return Inventario\BienBundle\Entity\Bien
     */
    public function getBien()
    {
        return $this->bien;
    }

    /**
     * Set estado
     *
     * @param Inventario\EstadoBundle\Entity\Estado $estado
     */
    public function setEstado(\Inventario\EstadoBundle\Entity\Estado $estado)
    {
        $this->estado = $estado;
    }

    /**
     * Get estado
     *
     * @return Inventario\EstadoBundle\Entity\Estado
     */
    public function getEstado()
    {
        return $this->estado;
    }

    /**
     * Set area
     *
     * @param Inventario\AreaBundle\Entity\Area $area
     */
    public function setArea(\Inventario\AreaBundle\Entity\Area $area)
    {
        $this->area = $area;
    }

    /**
     * Get area
     *
     * @return Inventario\AreaBundle\Entity\Area
     */
    public function getArea()
    {
        return $this->area;
    }

si ps esta asi....

Javier Vilcapaza

unread,
May 7, 2012, 2:13:17 AM5/7/12
to fabricio...@gmail.com, symfony-es
Catchable Fatal Error: Argument 1 passed to
Inventario\UbicacionBundle\Entity\Ubicacion::setArea() must be an
instance of Inventario\AreaBundle\Entity\Area, null given, called in
E:\inventario\src\Inventario\RegistroBundle\Controller\RegistroController.php
on line 79 and defined in
E:\inventario\src\Inventario\UbicacionBundle\Entity\Ubicacion.php line 119

este es el error... una vez quitado el bien=1

creo que el error esta en leer los datos del request y pasarlos a la
funcion

$request->request->get('area') //esto esta bien asi....?


ahora al setear... teniendo en cuenta la relacion estara bien o como
hay que guardar

$ubicacion= new Ubicacion();
$ubicacion->setArea($area);
$ubicacion->setBien($bien);
$ubicacion->setEstado($estado);
$ubicacion->setFechaRegistro(new \DateTime('today'));

$em_ubi= $this->getDoctrine()->getEntityManager();
$em_ubi->persist($ubicacion);
$em_ubi->persist($ubicacion->setArea());
$em_ubi->persist($ubicacion->setBien());
$em_ubi->persist($ubicacion->setEstado());
$em_ubi->flush();


una ayudiña pf ya toy hasta el cuello con esto...

Elio Rincón

unread,
May 7, 2012, 8:48:50 AM5/7/12
to symfo...@googlegroups.com
Trata de cambiar los parámetros en la función guardaUsuario a instancias de los objetos que estas manejando, de esta forma:

Inventario\AreaBundle\Entity\Area $area, 
\Inventario\BienBundle\Entity\Bien $bien, 
\Inventario\EstadoBundle\Entity\Estado $estado

y elimina estas variables: $area=1, $bien=1, $estado=1

German Macas

unread,
May 7, 2012, 4:12:59 PM5/7/12
to symfo...@googlegroups.com
Q tal...

Tienes que borrarle de la entidad Ubicacion, en el metodo SetArea(<Inventario\AreaBundle\Entity\Area > $area)
dejale solo:  SetArea($area)... y debería funcionaar...


Att. Germán Macas..
@gerod006

> Date: Mon, 7 May 2012 01:13:17 -0500
> From: jvjso...@gmail.com
> To: fabricio...@gmail.com; symfo...@googlegroups.com
> Subject: Re: [symfony-es] 'Necesito Ayuda' - - Catchable Fatal Error: Argument 1 passed

Mauricio Loyola Tirado

unread,
May 7, 2012, 5:11:02 PM5/7/12
to symfo...@googlegroups.com

Hola:

 

Prueba con este código:

 

$ubicacion= new Ubicacion();

$ubicacion->setArea($area);
$ubicacion->setBien($bien);
$ubicacion->setEstado($estado);

$ubicacion->setFechaRegistro(new \DateTime('now'));

$em = $this->getDoctrine()->getEntityManager();

$em->persist($ubicacion);

$em->flush();


Saludos

 

Mauricio

Javier vilcapaza luque

unread,
May 8, 2012, 9:44:23 PM5/8/12
to symfo...@googlegroups.com

Gracias a todos...

Bueno lo que hice es esto

$this->guardaUbicacion($entity->getArea() ,$entity->getEstado() ,$entity->getBien()  )

Con esto y los set guardando en la ubicacion....

Todo funciona....

Rolando Ramírez

unread,
Jun 4, 2012, 7:31:03 PM6/4/12
to symfo...@googlegroups.com
hola tengo tu mismo problema, podrias poner el codigo completo de tu correccion para guiarme? por favor.
Reply all
Reply to author
Forward
0 new messages