3
Hello I have the following code:
Old code:
public function historicoAction() {
$entity = new Intervencao();
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('RoqSysControlManutencaoBundle:Intervencao')->findAll();
$maquinas = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->findAll();
$prevista = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();
$entity->setDescricao($prevista->getDescricao());
return array(
'entity' => $entity,
'entities' => $entities,
'maquinas' => $maquinas,
);
}
You’re making the following mistake:
Error: Call to a Member Function getDescription() on a non-object in /var/www/roqsys/src/Roqsys/Control/Manutencaobundle/Controller/Intervencaocontroller.php line 76
Edit**
New code:
I tried the following:
public function historicoAction() {
$entity = new Intervencao();
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('RoqSysControlManutencaoBundle:Intervencao')->findAll();
$maquinas = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->findAll();
$prevista = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();
var_dump($prevista);
foreach($prevista as $obj) {
echo $prevista->getDescricao();
}
$entity->setDescricao($prevista->getDescricao());
return array(
'entity' => $entity,
'entities' => $entities,
'prevista' => $prevista,
'maquinas' => $maquinas,
);
}
And yet you make the same mistake.
Check if the line
$prevista = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();
Returns a valid object.– Pedro Henrique
Check that your entity (Entity) has the get method defined
– Adir Kuhn
@Adir Kunhn a Entity intervencao ou previsto????
– Catarina Silvestre
@Catarinasilvestre in the $provided
– Adir Kuhn
Ahh, now that I’ve seen findAll() it will return an Array of Objects, then you have to do a foreach to give a get of each element
– Adir Kuhn
@Pedro Henrique the line is returning an object, is reporting the predicted.
– Catarina Silvestre
@Adir Kuhn as??????
– Catarina Silvestre