Foros del Web » Programando para Internet » PHP » Symfony »

[SOLUCIONADO] No muestra nada después de haber hecho un crud

Estas en el tema de No muestra nada después de haber hecho un crud en el foro de Symfony en Foros del Web. Buenas noches, he hecho un CRUD de mi entidad ROLES y al entrar en la ruta http://localhost:8888/dipro3d/web/ap...p/admin/roles/ no me sale nada de nada, solo el ...
  #1 (permalink)  
Antiguo 09/11/2015, 13:40
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
No muestra nada después de haber hecho un crud

Buenas noches, he hecho un CRUD de mi entidad ROLES y al entrar en la ruta http://localhost:8888/dipro3d/web/ap...p/admin/roles/ no me sale nada de nada, solo el background de la pagina base

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()
        ;
    }
}
routing.yml

index_admin:
pattern: /admin
defaults: { _controller: TMKAdminBundle:Default:index }

TMKAnnotations:
resource: "@TMKAdminBundle/Controller/"
prefix: /
type: annotation
  #2 (permalink)  
Antiguo 09/11/2015, 15:19
 
Fecha de Ingreso: enero-2013
Ubicación: Santa Fe, VT
Mensajes: 68
Antigüedad: 11 años, 2 meses
Puntos: 2
Respuesta: No muestra nada después de haber hecho un crud

Bueno tal vez sea, por que no estas renderizando la pagina con un $this->render(); (en el indexAction)

EDIT: tambien podes usar la anotacion @Template y tu codigo funcionaria bien, pareciese como si lo hubieras hecho pensando en eso, aca te dejo un link a la documentacion
http://symfony.com/doc/current/bundl...ions/view.html

Última edición por molinasergio91; 09/11/2015 a las 15:35
  #3 (permalink)  
Antiguo 10/11/2015, 01:53
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: No muestra nada después de haber hecho un crud

No lo hice yo, lo generé automaticamente por el terminal, por eso me parece raro que no funcione, he metdo el template y tampoco

Código PHP:
/**
     * Lists all Roles entities.
     *
     * @Route("/", name="admin_role")
     * @Method("GET")
     * @Template("TMKAdminBundle:Roles:index.html.twig")
     */
    
public function indexAction()
    {
        
$em $this->getDoctrine()->getManager();

        
$entities $em->getRepository('TMKAdminBundle:Roles')->findAll();

        return array(
            
'entities' => $entities,
        );
    } 
  #4 (permalink)  
Antiguo 10/11/2015, 03:58
 
Fecha de Ingreso: enero-2013
Ubicación: Santa Fe, VT
Mensajes: 68
Antigüedad: 11 años, 2 meses
Puntos: 2
Respuesta: No muestra nada después de haber hecho un crud

ohhhhh me equivoque yo, disculpa era un crud, nunca habia hecho uno, perdon.
Esta tarde voy a leer un poco sobre eso y ver si te puedo ayudar, por ahora ignora mi respuesta
  #5 (permalink)  
Antiguo 10/11/2015, 04:54
Avatar de Jose_GZ  
Fecha de Ingreso: abril-2015
Mensajes: 5
Antigüedad: 9 años
Puntos: 0
Respuesta: No muestra nada después de haber hecho un crud

Buenas, te has fijado que el namespace y los use no los tienes bien definidos?

Código:
namespace TMKAdminBundleController;

use SymfonyComponentHttpFoundationRequest;
use SymfonyBundleFrameworkBundleControllerController;
use SensioBundleFrameworkExtraBundleConfigurationMethod;
use SensioBundleFrameworkExtraBundleConfigurationRoute;
use SensioBundleFrameworkExtraBundleConfigurationTemplate;
use TMKAdminBundleEntityRoles;
use TMKAdminBundleFormRolesType;
Debería ser
Código:
namespace TMK\AdminBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
... etc
Por otra parte está claro que tienes que utilizar render para que se muestre tu plantilla Twig, yo lo he hecho siempre con render pero con la anotación debería funcionarte igualmente. Comprueba lo de los use.

Un saludo
  #6 (permalink)  
Antiguo 10/11/2015, 12:04
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: No muestra nada después de haber hecho un crud

Los use y el namespace estan bien puestos, pero parece que al copiar el código en el foro se come las barras, así que eso no es tio, si fuese eso, no creo que funcionara nada. Gracias ;)
  #7 (permalink)  
Antiguo 11/11/2015, 12:53
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: No muestra nada después de haber hecho un crud

Solucionado, error mio jajaja, yo tenía el el html base {% block content %} y el crud lo genera con {% block body %}......¿Como no me he podido dar cuenta? jajaja

PD: Perdon por las molestias y gracias

Etiquetas: crud, hecho, muestra, nada
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:30.