pascalkleindienst/form-list-generator

一个小型库,可以轻松将数据以表格列表或表单的形式显示。其主要应用领域是管理/后端应用程序。

v1.3.0 2017-08-17 09:21 UTC

This package is not auto-updated.

Last update: 2024-09-15 03:39:35 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Code Style Total Downloads

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.mddocs/list.md

本地化

您还可以将消息翻译成其他语言。您只需设置一个可调用的 translator 属性,该属性将处理翻译即可

$form->setTranslator('gettext');
$list->setTranslator('gettext');

上面的例子使用了 gettext(),但您可以使用任何其他可调用的值,如 [$translator, 'trans']your_custom_function()

测试

$ composer test

贡献

请参阅 CONTRIBUTING 获取详细信息。

安全

如果您发现任何安全相关的问题,请通过电子邮件 mail@pascalkleindienst.de 而不是使用问题跟踪器来报告。

致谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件