binaryspanner / quickforms
A Symfony bundle to allow the creation of forms from YML files.
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.0
- symfony/config: ^3.2
- symfony/dependency-injection: ^3.2
- symfony/filesystem: ^3.2
- symfony/form: ^3.2
- symfony/http-kernel: ^3.2
- symfony/yaml: ^3.2
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4
- phpmd/phpmd: ^2.6
- phpspec/prophecy: ^1.7
- phpunit/phpunit: ^6.1
- sebastian/phpcpd: ^3.0
- squizlabs/php_codesniffer: ^3.0
- symfony/phpunit-bridge: 3.3.x-dev
- symfony/symfony: ^3.2
This package is not auto-updated.
Last update: 2024-04-27 23:16:57 UTC
README
Quick Forms
A Symfony bundle to allow the creation of forms from YML files.
Installation
The bundle can be installed using Composer:
composer require binaryspanner/quickforms
Use
First the bundle needs registered in the Symfony app's kernel:
// app/AppKernel.php public function registerBundles() { $bundles = [ // ... new BinarySpanner\QuickForms\QuickFormsBundle(), ]; // ... }
When using the default settings the bundle will search for form files in Resources/forms
in
the kernel's root directory (normally "path-to-Symfony-project"/app/
).
To load form files the filenames have to be added to the bundle's settings in config.yml
:
# app/config/config.yml # ... quick_forms: file_names: [ 'file1.yml', 'file2.yml', ...]
An example form file can be found in the bundle's Resources/forms
directory.
This form file will be loaded by default when the bundle's file_names
property is unset in
config.yml
.
The directories the bundle searches in can be changed by modifying the root_paths
and/or
directory_paths
bundle settings in config.yml
:
# app/config/config.yml # ... quick_forms: root_paths: [ '%kernel.root_dir%', '%kernel.root_dir%/../src' ] directory_paths: [ 'custom/forms' ] file_names: [ 'file1.yml', 'file2.yml', ...]
Note that absolute paths can be used in the directory_paths
setting.
Once the form layout files have been setup a view template needs to be created - if you're using Twig you can create Symfony forms as normal:
{# app/Resources/views/quickform/form.html.twig #} {% extends 'base.html.twig' %} {% block body %} Form One: {% form_theme forms.example_form_one.view forms.example_form_one.theme %} {{ form_start(forms.example_form_one.view) }} {{ form_widget(forms.example_form_one.view) }} {{ form_end(forms.example_form_one.view) }} Form Two: {% form_theme forms.example_form_two.view forms.example_form_two.theme %} {{ form_start(forms.example_form_two.view) }} {{ form_widget(forms.example_form_two.view) }} {{ form_end(forms.example_form_two.view) }} {% endblock %}
Finally the views need to be loaded in the controller:
// src/AppBundle/Controller/DefaultController.php // ... /** * @Route("/quickforms", name="quickforms") */ public function quickForms() { $quickForms = $this->get('quick_forms'); $forms = $quickForms->loadForms(); return $this->render('quickform/form.html.twig', array( 'forms' => $forms )); }