xm/form-bundle
Composer 安装命令:
composer require xm/form-bundle
包简介
A few helpers to make processing (creating, saving, errors, etc) forms simpler.
README 文档
README
A few helpers to make processing (creating, saving, errors, etc) forms simpler.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ php composer.phar require xm/form-bundle
This command requires Composer.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new XM\FormBundle\XMFormBundle(), ); // ... } }
Step 3: Add Service Alias
Adding the following will make the call to the service shorter:
form_handler: '@xm_form.handler'
Usage
Get the form handler
$formHandler = $this->get('form_handler');
Create the form
$form = $formHandler->getForm(
EntityFormType::class,
$entity,
$request
);
Process form & save entity
if ($formHandler->processForm($form, $entity, '[entity name]')) {
// entity valid and saved successfully, redirect
}
Retrieve validation errors/messages as an array
This is useful when passing the validation messages to JS through JSON.
$errors = FormErrors::flatten($form)
This will return an array of the errors in the format of:
array(
0 => array(
'Global Error 1',
),
'field_name' => array(
'Field Error 1',
'Field Error 2',
...
),
...
)
统计信息
- 总下载量: 322
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-05