piwi91/form-handler

为Symfony表单组件实现的表单处理器

v1.0.0 2015-09-17 17:58 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:42:59 UTC


README

Build Status

这是一个表单处理器的实现,我将其与Symfony表单组件结合使用。

点击此处查看我关于表单处理器的博客文章。

用法

实现FormHandlerInterface或扩展AbstractFormHandler并实现postProcess方法。

您可以使用try/catch来捕获验证异常。

示例

public function anActionInAController(Request $request)
{
    $formHandler = new MyFancyFormHandler($formFactory, $form);

    $form = $formHandler->form();

    if ($request->isMethod('POST') {
        try {
            $formHandler->process($form, $request);
        } catch (ValidationException $e) {
            // Do something with the validation... or not ;-) (and render the page including the validation errors)
        }
    }

    return $this->render('my_view.html.twig', ['form' => $form->createView()]);
}