piwi91 / form-handler
为Symfony表单组件实现的表单处理器
v1.0.0
2015-09-17 17:58 UTC
Requires
- symfony/form: ^2.3
- symfony/http-foundation: ^2.3
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2024-09-14 17:42:59 UTC
README
这是一个表单处理器的实现,我将其与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()]);
}