Witam. Jak za pomocą formularza wysłać błędy do szablonu. Próbowałem już chyba wszystkiego . Mam symfony 3.3.
akcja kontrolera:
public function assetAction()
{
$em = $this->getDoctrine()->getEntityManager();
$task = new asset();
$form = $this->createFormBuilder($task)
->add('model', TextType
::class, array( "error_bubbling" => true,
'required' => false,
'constraints' => array(new NotBlank
(), new Length
(array('min' => 30))) ))
->add('save', SubmitType
::class, array('label' => 'Create Task')) ->getForm();
'form' => $form->createView());
}
plik Twig:
{{ form_start(form, {'attr' : {'style' : 'color:black' } } ) }}
{{ form_errors(form.model) }}
{{ form_widget(form.model, {'attr' : {'class' : 'form-inline','autocomplete':'off' } }) }}
{{ form_row(form.save, { 'label': 'Szukaj' }) }}
{% endblock %}
Plik konfiguracyjny:
validation: { enable_annotations: true }
Plik entity asset:
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints
as Assert;class Asset
{
protected $model;
public function getModel()
{
return $this->model;
}
public function setModel($model)
{
$this->model= $model;
}
}
Co jest źle?? Ponieważ nie mogę wygenerować błędów w formularzu