collection-crud/src/Controller/CameraTypeController.php

139 lines
3.4 KiB
PHP

<?php
namespace App\Controller;
use App\Entity\CameraType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Cameratype controller.
*
* @Route("camera-type")
*/
class CameraTypeController extends Controller
{
/**
* Lists all cameraType entities.
*
* @Route("/", name="camera-type_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$cameraTypes = $em->getRepository('App:CameraType')->findBy([], [
'type' => 'ASC'
]);
return $this->render('cameratype/index.html.twig', array(
'cameraTypes' => $cameraTypes,
));
}
/**
* Creates a new cameraType entity.
*
* @Route("/new", name="camera-type_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$cameraType = new Cameratype();
$form = $this->createForm('App\Form\CameraTypeType', $cameraType);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($cameraType);
$em->flush();
return $this->redirectToRoute('camera-type_show', array('id' => $cameraType->getId()));
}
return $this->render('cameratype/new.html.twig', array(
'cameraType' => $cameraType,
'form' => $form->createView(),
));
}
/**
* Finds and displays a cameraType entity.
*
* @Route("/{id}", name="camera-type_show")
* @Method("GET")
*/
public function showAction(CameraType $cameraType)
{
$deleteForm = $this->createDeleteForm($cameraType);
return $this->render('cameratype/show.html.twig', array(
'cameraType' => $cameraType,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing cameraType entity.
*
* @Route("/{id}/edit", name="camera-type_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, CameraType $cameraType)
{
$deleteForm = $this->createDeleteForm($cameraType);
$editForm = $this->createForm('App\Form\CameraTypeType', $cameraType);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('camera-type_edit', array('id' => $cameraType->getId()));
}
return $this->render('cameratype/edit.html.twig', array(
'cameraType' => $cameraType,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a cameraType entity.
*
* @Route("/{id}", name="camera-type_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, CameraType $cameraType)
{
$form = $this->createDeleteForm($cameraType);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($cameraType);
$em->flush();
}
return $this->redirectToRoute('camera-type_index');
}
/**
* Creates a form to delete a cameraType entity.
*
* @param CameraType $cameraType The cameraType entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(CameraType $cameraType)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('camera-type_delete', array('id' => $cameraType->getId())))
->setMethod('DELETE')
->getForm();
}
}