victormacko/symfony-smarty-standalone-forms 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

统计信息

  • 总下载量: 490
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-10-06