正如标题已经说过的那样,我似乎无法找到一种方式来显示我的内联形式。 这是我的模板:
{% extends 'base.html.twig' %}
{% block title %}Personeneinträge{% endblock %}
{% block body %}
<div class='container'>
<h1>Personeneinträge</h1>
<form class='form-inline' method="post">
{{ form_start(form)}}
{{ form_widget(form)}}
{{ form_end(form)}}
</form>
这是我的控制器:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Users;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class DefaultController extends Controller
{
/**
* @Route("/homepage", name="homepage")
*/
public function listAction(Request $request)
{
$users = new Users();
$userssrc = null;
$name = null;
$session = $request->getSession();
$defaultData = array('message' => 'wut');
$formsearch = $this->createFormBuilder($defaultData)
->add('Suche', TextType::class, array('label'=>'Suche', 'attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('submit', SubmitType::class, array('label'=>'suchen','attr'=>array('class'=>'btn btn-primary')))
->add('Zurücksetzten', SubmitType::class, array('label'=>'zurücksetzten', 'attr'=> array('class'=>'btn btn-default')))
->getForm();
$formsearch->handleRequest($request);
if($formsearch->isSubmitted() && $formsearch->isValid()){
$name = $formsearch['Suche']->getData();
dump($name);
$em=$this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT u
FROM AppBundle:Users u
WHERE u.vorname = :name
OR u.nachname = :name')->setParameter('name', $name);
$userssrc = $query->getResult();
if ($formsearch->get('Zurücksetzten')->isClicked()){
$textsa = 'Zurücksetzten geklickt';
dump($textsa);
return $this->redirectToRoute('homepage');
}
}
else{
$vae = 'failed form submission';
dump($vae);
}
类.form-inline仅显示同一行上的标签和文本字段,按钮位于下方。 My rendered page:
我也尝试过用CSS和“display:inline”,但没有区别。 我很感激任何提示:) 表单看起来像这样呈现:
或者像这样: