victormacko/symfony-smarty-standalone-forms
Composer 安装命令:
composer require victormacko/symfony-smarty-standalone-forms
包简介
README 文档
README
Implementation of Symfony2 forms component with different templating engines
The 'views/Form' directory contains a bootstrap implementation (horizontal) of the symfony2 bootstrap created in Twig (https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig & https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig)
The 'ControllerSymfonyFormTrait.php' file contains a trait to include in your base controller, which adds the 'createForm' and 'createFormBuilder' functions, as detailed here; http://symfony.com/doc/current/forms.html
Smarty
web/index.php contains a 'demo' controller to pull together the various components, create a Smarty instance and then output it.
Volt
Volt support is included
In the register-engine block (in services.php), include the following line;
$view->registerEngines(array( '.volt' => function ($view, $di) use ($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array( 'compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'compileAlways' => true )); $compiler = $volt->getCompiler(); SymfonyFormHelper::registerFormPluginsWithVolt($compiler); return $volt; }, '.phtml' => 'Phalcon\Mvc\View\Engine\Php' ));
Within your controller, to create the form, you just need to include the following;
$form = $this ->createFormBuilder() ->add('testField', \SymfonyStandaloneForms\Type\TextType::class, [ 'constraints' => [ new \Symfony\Component\Validator\Constraints\Length(['min' => 2]) ] ]) ->add('submit', \Symfony\Component\Form\Extension\Core\Type\SubmitType::class) ->getForm(); $form->handleRequest(\Symfony\Component\HttpFoundation\Request::createFromGlobals()); if($form->isSubmitted()) { if($form->isValid()) { // get data from field; $data = $form->get('testField')->getData(); } } $this->view->form2 = $form->createView();
Your volt code will then need to include the standard template code to render forms - eg;
{{ form_start(form, {'attr': {'novalidate': 'novalidate'} }) }}
{{ form_row(form['testField']) }}
{{ form_rest(form) }}
{{ form_end(form) }}
Plain PHP
There's also a plain php form rendering option also if smarty isn't your thing.
victormacko/symfony-smarty-standalone-forms 适用场景与选型建议
victormacko/symfony-smarty-standalone-forms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 490 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 victormacko/symfony-smarty-standalone-forms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 victormacko/symfony-smarty-standalone-forms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 490
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-10-06