pascalkleindienst / form-list-generator
Small library to easily display data as a table-list or a form. Its main application area is in admin/backend applications.
Requires
- php: ~5.5|~5.6|~7.0
- adamwathan/form: ^0.9.0
- symfony/yaml: ^3.3
- weew/helpers-array: ^1.3
Requires (Dev)
- phpunit/phpunit: ~4.0||~5.0
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-11-10 04:32:49 UTC
README
FormListGenerator is a small library to easily display data as a table-list or a form. Its main application area is in admin/backend applications.
Install
Via Composer
$ composer require pascalkleindienst/form-list-generator
Usage
use PascalKleindienst\FormListGenerator\Generators\ListGenerator; use PascalKleindienst\FormListGenerator\Generators\FormGenerator; use PascalKleindienst\FormListGenerator\Support\Config; # set the root path of the application and optionally a baseUrl Config::set([ 'root' => dirname(__FILE__), 'baseUrl' => 'http://example.com' ]); // Init Generators with yaml config $list = new ListGenerator('list.yaml'); $form = new FormGenerator('form.yaml'); // Alternatively, we can use the load method (useful when you put the generator class in a container) $list = new ListGenerator(); $form = new FormGenerator(); $list = $list->load('list.yaml'); $form = $form->load('form.yaml'); // Render List # some example date, usually fetched from your DB $listData = [ [ 'id' => 1, 'full_name' => 'John Doe', 'age' => 42, 'created_at' => time(), 'content' => 'lorem ipsum', 'recursive' => [ # accessed via dot notation in yaml => recursive.test or recursive.foo 'test' => 'Recursive Testing', 'foo' => 'Foo' ] ], [ 'id' => 2, 'full_name' => 'John Doe', 'age' => 42, 'created_at' => time(), 'content' => 'lorem ipsum', 'recursive' [ # accessed via dot notation in yaml => recursive.test or recursive.foo 'test' => 'Recursive Testing', 'foo' => 'Foo' ] ] ]; $list->render($listData); // Render the form $formData = [ 'id' => 1, 'full_name' => 'John Doe', 'age' => 42, 'created_at' => time(), 'content' => 'lorem ipsum', 'recursive' [ # accessed via dot notation in yaml => recursive.test or recursive.foo 'test' => 'Recursive Testing', 'foo' => 'Foo' ] ]; $form->render($formData);
Configuration
See docs/form.md and docs/list.md
Localization
You're also able to translate your message to another language. The only thing one must do is to set the attribute translator as a callable that will handle the translation:
$form->setTranslator('gettext'); $list->setTranslator('gettext');
The example above uses gettext()
but you can use any other callable value, like [$translator, 'trans']
or your_custom_function()
.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mail@pascalkleindienst.de instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.