0
Here’s the thing, I’ve got an Entity Machine and another Predicted Entity, and they’re both in the same Bundle. What I intended was that in machine 3, which has already been created, every 100 thousand was changed the oil of the distribution chain.
The code of the Machine.php
<?php
namespace RoqSys\Control\ManutencaoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use RoqSys\Control\ControlBundle\Entity\Posto as Posto;
/**
* Maquina
*
*
* @ORM\Entity(repositoryClass="RoqSys\Control\ManutencaoBundle\Entity\MaquinaRepository")
*
*/
class Maquina
{
/**
* @var
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO") integer
*/
private $id;
/**
* @var integer
*
* @ORM\Column(type="bigint", nullable=true, name="ciclo")
*/
private $ciclo;
/**
* @var \DateTime
*
* @ORM\Column(type="date", nullable=true, name="ultima")
*/
private $ultima;
/**
* @ORM\OneToOne(targetEntity="RoqSys\Control\ControlBundle\Entity\Posto", inversedBy="maquina")
* @ORM\JoinColumn(name="posto_id", referencedColumnName="id", unique=true)
*/
private $posto;
/**
* @ORM\OneToMany(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Intervencao", mappedBy="maquina")
*/
private $intervencao;
/**
* @ORM\OneToMany(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Prevista", mappedBy="maquina")
*/
private $prevista;
/**
* Set id
*
* @param integer $id
* @return Maquina
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set ciclo
*
* @param integer $ciclo
* @return Maquina
*/
public function setCiclo($ciclo)
{
$this->ciclo = $ciclo;
return $this;
}
/**
* Get ciclo
*
* @return integer
*/
public function getCiclo()
{
return $this->ciclo;
}
/**
* Set ultima
*
* @param \DateTime $ultima
* @return Maquina
*/
public function setUltima($ultima)
{
$this->ultima = $ultima;
return $this;
}
/**
* Get ultima
*
* @return \DateTime
*/
public function getUltima()
{
return $this->ultima;
}
/**
* Set posto
*
* @param Posto $posto
* @return Maquina
*/
public function setPosto($posto)
{
$this->posto = $posto;
return $this;
}
/**
* Get posto
*
* @return Posto
*/
public function getPosto()
{
return $this->posto;
}
public function __toString() {
return "TESTE";
}
}
The code of the Hostcontroller
<?php
namespace RoqSys\Control\ManutencaoBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use RoqSys\Control\ManutencaoBundle\Entity\Maquina;
use RoqSys\Control\ControlBundle\Entity\Posto;
use RoqSys\Control\ManutencaoBundle\Form\MaquinaType;
/**
* Maquina controller.
*
* @Route("/manutencao/maquina")
*/
class MaquinaController extends Controller {
/**
* Lists all Maquina entities.
*
* @Route("/", name="manutencao_maquina")
* @Method("GET")
* @Template()
*/
public function indexAction() {
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->findAll();
return array(
'entities' => $entities,
);
}
/**
* Creates a new Intervencao entity.
*
* @Route("/{id}/create", name="manutencao_maquina_create")
* @Method("GET")
* @Template("RoqSysControlManutencaoBundle:Maquina:new.html.twig")
*/
public function createAction($id)
{
$maquina = new Maquina();
$em = $this->getDoctrine()->getManager();
$posto = $em->getRepository('RoqSysControlControlBundle:Posto')->find($id);
$maquina->setPosto($posto);
$em->persist($maquina);
$em->persist($posto);
$em->flush();
return $this->redirect($this->generateUrl('manutencao_maquina_show', array('id' => $maquina->getId())));
}
/**
* Creates a form to create a Maquina entity.
*
* @param Maquina $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Maquina $entity) {
$form = $this->createForm(new MaquinaType(), $entity, array(
'action' => $this->generateUrl('manutencao_maquina_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new Maquina entity.
*
* @Route("/new", name="manutencao_maquina_new")
* @Method("GET")
* @Template()
*/
public function newAction() {
$em = $this->getDoctrine()->getManager();
$entity = new Maquina();
$form = $this->createCreateForm($entity);
$postos = $em->getRepository('RoqSysControlControlBundle:Posto')->findAll();
return array(
'entity' => $entity,
'postos' => $postos,
'form' => $form->createView(),
);
}
/**
* Finds and displays a Maquina entity.
*
* @Route("/{id}", name="manutencao_maquina_show")
* @Method("GET")
* @Template()
*/
public function showAction($id) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Maquina entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing Maquina entity.
*
* @Route("/{id}/edit", name="manutencao_maquina_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Maquina entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Creates a form to edit a Maquina entity.
*
* @param Maquina $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Maquina $entity) {
$form = $this->createForm(new MaquinaType(), $entity, array(
'action' => $this->generateUrl('manutencao_maquina_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing Maquina entity.
*
* @Route("/{id}", name="manutencao_maquina_update")
* @Method("PUT")
* @Template("RoqSysControlManutencaoBundle:Maquina:edit.html.twig")
*/
public function updateAction(Request $request, $id) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Maquina entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('manutencao_maquina_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a Maquina entity.
*
* @Route("/{id}", name="manutencao_maquina_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, $id) {
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Maquina entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('manutencao_maquina'));
}
/**
* Creates a form to delete a Maquina entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id) {
return $this->createFormBuilder()
->setAction($this->generateUrl('manutencao_maquina_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}
The code of Prevista.php
<?php
namespace RoqSys\Control\ManutencaoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Prevista
*
*
* @ORM\Entity(repositoryClass="RoqSys\Control\ManutencaoBundle\Entity\PrevistaRepository")
*/
class Prevista
{
/**
* @var integer
*
* @ORM\Column(type="integer", name="id")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(type="integer", nullable=true, name="contagem")
*/
private $contagem;
/**
* @var integer
*
* @ORM\Column(type="integer", nullable=true, name="duracao")
*/
private $duracao;
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true, name="titulo")
*/
private $titulo;
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true, name="ficha")
*/
private $ficha;
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true, name="descricao")
*/
private $descricao;
/**
* @var \DateTime
*
* @ORM\Column(type="date", nullable=true, name="ultima")
*/
private $ultima;
/**
* @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="prevista")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id")
*/
private $maquina;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set contagem
*
* @param integer $contagem
* @return Prevista
*/
public function setContagem($contagem)
{
$this->contagem = $contagem;
return $this;
}
/**
* Get contagem
*
* @return integer
*/
public function getContagem()
{
return $this->contagem;
}
/**
* Set duracao
*
* @param integer $duracao
* @return Prevista
*/
public function setDuracao($duracao)
{
$this->duracao = $duracao;
return $this;
}
/**
* Get duracao
*
* @return integer
*/
public function getDuracao()
{
return $this->duracao;
}
/**
* Set titulo
*
* @param string $titulo
* @return Prevista
*/
public function setTitulo($titulo)
{
$this->titulo = $titulo;
return $this;
}
/**
* Get titulo
*
* @return string
*/
public function getTitulo()
{
return $this->titulo;
}
/**
* Set ficha
*
* @param string $ficha
* @return Prevista
*/
public function setFicha($ficha)
{
$this->ficha = $ficha;
return $this;
}
/**
* Get ficha
*
* @return string
*/
public function getFicha()
{
return $this->ficha;
}
/**
* Set descricao
*
* @param string $descricao
* @return Prevista
*/
public function setDescricao($descricao)
{
$this->descricao = $descricao;
return $this;
}
/**
* Get descricao
*
* @return string
*/
public function getDescricao()
{
return $this->descricao;
}
/**
* Set ultima
*
* @param \DateTime $ultima
* @return Prevista
*/
public function setUltima($ultima)
{
$this->ultima = $ultima;
return $this;
}
/**
* Get ultima
*
* @return \DateTime
*/
public function getUltima()
{
return $this->ultima;
}
/**
* Set maquina
*
* @param Maquina $maquina
* @return Maquina
*/
public function setMaquina($maquina)
{
$this->maquina = $maquina;
return $this;
}
/**
* Get maquina
*
* @return \Maquina
*/
public function getMaquina()
{
return $this->maquina;
}
}
The code of Previstacontroller
<?php
namespace RoqSys\Control\ManutencaoBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use RoqSys\Control\ManutencaoBundle\Entity\Prevista;
use RoqSys\Control\ManutencaoBundle\Form\PrevistaType;
/**
* Prevista controller.
*
* @Route("/manutencao/prevista")
*/
class PrevistaController extends Controller
{
/**
* Lists all Prevista entities.
*
* @Route("/", name="manutencao_prevista")
* @Method("GET")
* @Template()
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();
return array(
'entities' => $entities,
);
}
/**
* Creates a new Prevista entity.
*
* @Route("/", name="manutencao_prevista_create")
* @Method("POST")
* @Template("RoqSysControlManutencaoBundle:Prevista:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new Prevista();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('manutencao_prevista_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Creates a form to create a Prevista entity.
*
* @param Prevista $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Prevista $entity)
{
$form = $this->createForm(new PrevistaType(), $entity, array(
'action' => $this->generateUrl('manutencao_prevista_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new Prevista entity.
*
* @Route("/new", name="manutencao_prevista_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$em = $this->getDoctrine()->getManager();
$entity = new Prevista();
$form = $this->createCreateForm($entity);
$entities = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->findAll();
return array(
'entity' => $entity,
'entities' => $entities,
'form' => $form->createView(),
);
}
/**
* Finds and displays a Prevista entity.
*
* @Route("/{id}", name="manutencao_prevista_show")
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Prevista entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing Prevista entity.
*
* @Route("/{id}/edit", name="manutencao_prevista_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Prevista entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Creates a form to edit a Prevista entity.
*
* @param Prevista $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Prevista $entity)
{
$form = $this->createForm(new PrevistaType(), $entity, array(
'action' => $this->generateUrl('manutencao_prevista_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing Prevista entity.
*
* @Route("/{id}", name="manutencao_prevista_update")
* @Method("PUT")
* @Template("RoqSysControlManutencaoBundle:Prevista:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Prevista entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('manutencao_prevista_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a Prevista entity.
*
* @Route("/{id}", name="manutencao_prevista_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Prevista entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('manutencao_prevista'));
}
/**
* Creates a form to delete a Prevista entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('manutencao_prevista_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}
The code Previta.new
{# src/RoqSys/Control/ManutencaoBundle/Resources/views/Default/Prevista/new.html.twig #}
{% extends 'RoqSysBaseBundle:Default:base.html.twig' %}
{% form_theme form _self %}
{% block integer_widget %}
<div class="col-md-6 integer_widget">
{% set type = type|default('number') %}
{{ block('form_widget_simple') }}
</div>
{% endblock %}
{% block content -%}
<h1>Nova Previsão</h1>
<br>
<ul class="record_actions">
<li>
<a href="{{ path('manutencao_prevista') }}">
Voltar para a lista
</a>
</li>
</ul>
<br>
{{ form_start(form) }}
<div id="roqsys_control_manutencaobundle_prevista">
<div class="form-group">
<div class="col-md-12">
<br>
{{ form_label(form.contagem,'Contagem',{ 'label_attr': {'class':' col-sm-6 col-lg-2 text-right'} }) }}
{{ form_errors(form.contagem) }}
{{ form_widget(form.contagem) }}
</div>
<div class="col-sm-12">
<br>
{{ form_label(form.duracao,{ 'label_attr': {'class':' col-sm-6 col-lg-2 text-right'} }) }}
{{ form_errors(form.duracao) }}
{{ form_widget(form.duracao) }}
</div>
<div class="col-sm-12">
<br>
{{ form_label(form.titulo,'Título',{ 'label_attr': {'class':' col-sm-6 col-lg-2 text-right'} }) }}
{{ form_errors(form.titulo) }}
{{ form_widget(form.titulo) }}
</div>
<div class="col-sm-12">
<br>
{{ form_label(form.ficha,'Ficha',{ 'label_attr': {'class':' col-sm-6 col-lg-2 text-right'} }) }}
{{ form_errors(form.ficha) }}
{{ form_widget(form.ficha) }}
</div>
<div class="col-sm-12">
<br>
{{ form_label(form.descricao,'Descrição',{ 'label_attr': {'class':' col-sm-6 col-lg-2 text-right'} }) }}
{{ form_errors(form.descricao) }}
{{ form_widget(form.descricao) }}
</div>
<div class="col-sm-12">
<br>
{{ form_label(form.ultima,'Ultima',{ 'label_attr': {'class':' col-sm-6 col-lg-2 text-right'} }) }}
{{ form_errors(form.ultima) }}
{{ form_widget(form.ultima) }}
</div>
</div>
<div class="col-sm-12">
<label for="InputMaquina">Máquina</label
<select>
{% for maquina in entities %}
<option>
{{maquina.id}}
</option>
{% endfor %}
</select>
</div>
</div>
{{ form_end(form) }}
{% endblock %}
Okay, you’ve got all the codes, I’ve been around and around and I still can’t figure out where the problem is, and someone knows how to fix it or what’s going on please help me.
There’s a lot of code in that question!
– Wallace Maxters
but it has to be to see if you can help me figure out what the mistake is, what’s wrong and what to change.
– Catarina Silvestre
What would be "machine 3"? Would be machine id 3? And of 100,000 in 100,000, what? Machine cycles? Forecast counts?
– Rodrigo Rigotti
Yes it is machine with id 3. 100 thousand and 100 thousand is count.
– Catarina Silvestre