collection-crud/src/Controller/PreviouslyOwnedCameraContro...

75 lines
2.1 KiB
PHP

<?php
namespace CameraBundle\Controller;
use CameraBundle\Entity\PreviouslyOwnedCamera;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Previouslyownedcamera controller.
*
* @Route("previously-owned-camera")
*/
class PreviouslyOwnedCameraController extends Controller
{
/**
* Lists all previouslyOwnedCamera entities.
*
* @Route("/", name="previously-owned-camera_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$previouslyOwnedCameras = $em->getRepository('CameraBundle:PreviouslyOwnedCamera')->findBy([], [
'brand' => 'ASC',
'mount' => 'ASC',
'model' => 'ASC',
]);
return $this->render('previouslyownedcamera/index.html.twig', array(
'previouslyOwnedCameras' => $previouslyOwnedCameras,
));
}
/**
* Finds and displays a previouslyOwnedCamera entity.
*
* @Route("/{id}", name="previously-owned-camera_show")
* @Method("GET")
*/
public function showAction(PreviouslyOwnedCamera $previouslyOwnedCamera)
{
return $this->render('previouslyownedcamera/show.html.twig', array(
'previouslyOwnedCamera' => $previouslyOwnedCamera,
));
}
/**
* Displays a form to edit an existing previouslyOwnedCamera entity.
*
* @Route("/{id}/edit", name="previously-owned-camera_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, PreviouslyOwnedCamera $previouslyOwnedCamera)
{
$editForm = $this->createForm('CameraBundle\Form\PreviouslyOwnedCameraType', $previouslyOwnedCamera);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('previously-owned-camera_edit', array('id' => $previouslyOwnedCamera->getId()));
}
return $this->render('previouslyownedcamera/edit.html.twig', array(
'previouslyOwnedCamera' => $previouslyOwnedCamera,
'edit_form' => $editForm->createView(),
));
}
}