pascalkleindienst / form-list-generator
一个小型库,可以轻松将数据以表格列表或表单的形式显示。其主要应用领域是管理/后端应用程序。
v1.3.0
2017-08-17 09:21 UTC
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-09-15 03:39:35 UTC
README
FormListGenerator 是一个小型库,可以轻松将数据以表格列表或表单的形式显示。其主要应用领域是管理/后端应用程序。
安装
通过 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);
配置
请参阅 docs/form.md 和 docs/list.md
本地化
您还可以将消息翻译成其他语言。您只需设置一个可调用的 translator 属性,该属性将处理翻译即可
$form->setTranslator('gettext'); $list->setTranslator('gettext');
上面的例子使用了 gettext(),但您可以使用任何其他可调用的值,如 [$translator, 'trans'] 或 your_custom_function()。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件 mail@pascalkleindienst.de 而不是使用问题跟踪器来报告。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。