Stack Overflow en español Asked by dostoyevski on January 25, 2021
quiero mostrar una lista de nombres (que saco de una base de datos) en un formulario con su correspondiente boton de borrar y actualizar. Pero al añadir un campo al formulario de esta forma:->add('nombre',null,array('data' => $gen["name"],'label' =>'nombre', 'attr' => array('class' => 'className')))
me aparece como un cuadro de texto y yo lo que quiero es el texto sin mas, no se si me explico, no como un textbox, es decir no como un <input type="text">
sino mas bien como un <label >First name:</label>
Este es el codigo del controlador:
<?php
namespace AppBundleController;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentRoutingAnnotationRoute;
use AppBundleEntityGenus;
use SymfonyComponentHttpFoundationResponse;
use DoctrineORMToolsSetup;
use DoctrineORMEntityManager;
use AppBundleFormGenusFormType;
use SymfonyComponentFormExtensionCoreTypeAddressType;
use SymfonyComponentFormExtensionCoreTypeSubmitType;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormExtensionCoreTypeHiddenType;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage"))
*/
public function newAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$genuses = $em->getRepository('AppBundle:Genus')
->consulta(20);
foreach ($genuses as $gen)
{
$form = $this->createFormBuilder()
//->setAction($this->generateUrl('app_lucky_number'))
->setAction($this->generateUrl('homepage'))
->setMethod ("POST")
->add('nombre',null,array('data' => $gen["name"],'label' =>'nombre', 'attr' => array('class' => 'className')))
->add('id',HiddenType::class, ['data' => $gen["id"],])
->add('actualizar', SubmitType::class,array('label' => 'actualizar','attr' => array('class' => 'className')))
->add('borrar', SubmitType::class,array('label' => 'borrar','attr' => array('class' => 'className')))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$genus = $form->getData();
$id=$genus["id"];
if ($form->get('borrar')->isClicked())
{
$em = $this->getDoctrine()->getManager();
$genuses = $em->getRepository('AppBundle:Genus')
->borrar($id);
}
//return $this->render('genus/principal.html.twig',array('name'=>$name));
return $this->render('genus/principal.html.twig',array('id'=>$id));
}
$formularios[]=$form->createView();
}
return $this->render('genus/show.html.twig',['genuses'=>$formularios]);
}
}
?>
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP