RolesController.php
Código PHP:
<?php
namespace TMKAdminBundleController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyBundleFrameworkBundleControllerController;
use SensioBundleFrameworkExtraBundleConfigurationMethod;
use SensioBundleFrameworkExtraBundleConfigurationRoute;
use SensioBundleFrameworkExtraBundleConfigurationTemplate;
use TMKAdminBundleEntityRoles;
use TMKAdminBundleFormRolesType;
/**
* Roles controller.
*
* @Route("/admin/roles")
*/
class RolesController extends Controller
{
/**
* Lists all Roles entities.
*
* @Route("/", name="admin_role")
* @Method("GET")
* @Template()
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('TMKAdminBundle:Roles')->findAll();
return array(
'entities' => $entities,
);
}
/**
* Creates a new Roles entity.
*
* @Route("/", name="admin_role_create")
* @Method("POST")
* @Template("TMKAdminBundle:Roles:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new Roles();
$form = $this->createForm(new RolesType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('admin_role_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Displays a form to create a new Roles entity.
*
* @Route("/new", name="admin_role_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$entity = new Roles();
$form = $this->createForm(new RolesType(), $entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Finds and displays a Roles entity.
*
* @Route("/{id}", name="admin_role_show")
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('TMKAdminBundle:Roles')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Roles entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing Roles entity.
*
* @Route("/{id}/edit", name="admin_role_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('TMKAdminBundle:Roles')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Roles entity.');
}
$editForm = $this->createForm(new RolesType(), $entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Edits an existing Roles entity.
*
* @Route("/{id}", name="admin_role_update")
* @Method("PUT")
* @Template("TMKAdminBundle:Roles:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('TMKAdminBundle:Roles')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Roles entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new RolesType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('admin_role_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a Roles entity.
*
* @Route("/{id}", name="admin_role_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('TMKAdminBundle:Roles')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Roles entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('admin_role'));
}
/**
* Creates a form to delete a Roles entity by id.
*
* @param mixed $id The entity id
*
* @return Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
}
}
index_admin:
pattern: /admin
defaults: { _controller: TMKAdminBundle:Default:index }
TMKAnnotations:
resource: "@TMKAdminBundle/Controller/"
prefix: /
type: annotation