bpolaszek / formmetadatabundle
此包的最新版本(0.4)没有可用的许可信息。
0.4
2016-01-29 11:33 UTC
Requires
- php: >=5.4
README
该插件通过从其他地方定义的元数据(例如通过实体的注释或外部yaml文件)来简化表单字段的配置。通过控制器允许更通用的表单类型处理,使其能够处理动态实体/表单(例如用于CMS站点)。
查看表单字段 注释参考
注意:人们可能希望考虑使用Symfony2 Abstract Forms将表单配置外部化到控制器作为最佳实践。
注释示例
标准表单构建器
->add('dueDate', 'date', array('widget' => 'single_text'))
在实体中使用注释
/**
* @Form\Field("date", widget="single_text")
*/
具有一些基本表单注释的实体
use FlintLabs\Bundle\FormMetadataBundle\Configuration as Form;
use Symfony\Bundle\Validator\Constraints as Assert;
class Contact
{
/**
* @Form\Field("text")
* @Assert\NotBlank()
*/
public $name;
/**
* @Form\Field("textarea")
*/
public $message;
}
简单控制器
class MyController
{
public function contactAction()
{
$contact = new Contact();
$form = $this->get('form_metadata.mapper')->createFormBuilder($contact)->getForm();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as saving the task to the database
return $this->redirect($this->generateUrl('task_success'));
}
}
}
}
安装
更新您的deps文件
[Form-Metadata]
git=git@github.com:FlintLabs/Form-Metadata.git
target=/bundles/FlintLabs/Bundle/FormMetadataBundle
更新您的供应商
php bin/vendors update
更新您的自动加载器
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'FlintLabs\\Bundle\\FormMetadataBundle' => __DIR__.'/../vendor/bundles/',
// ...
));
注册包引用
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new FlintLabs\Bundle\FormMetadataBundle\FlintLabsFormMetadataBundle(),
// ...
);
}