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.
Via Composer
$ composer require pascalkleindienst/form-list-generator
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);
See docs/form.md and docs/list.md
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()
.
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email mail@pascalkleindienst.de instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.