listem / listem-php
Listem 是一个易于使用(但高度可定制)的 PHP 数据排序和过滤模块,可用于数据列表/表格/网格、报告或 API。
dev-master
2018-04-11 04:06 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ~4.8.36
This package is not auto-updated.
Last update: 2024-09-19 00:42:01 UTC
README
Listem 是一个易于使用(但高度可定制)的 PHP 数据排序和过滤模块(适用于 PHP >= 5.4),可用于数据列表/表格/网格、报告或 API。
安装
请确保您已安装 Composer,并从您的项目目录运行以下命令。
composer require listem/listem-php
通用用法
设置配置并初始化。
$config = [ 'filters' => [ 'name' => ['label' => 'Title'], 'content' => ['label' => 'Content', 'column' => ['content', 'summary']], 'state' => [ 'label' => 'State', 'type' => Listem\Filter::ENUM_INPUT, 'enums' => [ 1 => 'Active', 0 => 'Draft' ] ], 'created_at' => ['label' => 'Created On', 'type' => Listem\Filter::DATE], 'category' => ['label' => 'Category', 'type' => Listem\Filter::ENUM_SELECT] ], 'sorters' => [ 'name' => ['label' => 'Full Name', 'column' => 'users.name'], 'active' => ['label' => 'Active', 'column' => 'users.active'] ] ]; $list = new Listem\ListEntity($config, new Listem\Conditions\MySQL, new Listem\Params\Get); $filters = $list->getFilters(); $sorters = $list>getSorters(); $filterConditions = $filters->getConditions(); $sorterConditions = $sorters->getConditions(); $data = BlogPost::whereRaw($condition); ->orderBy($sorterConditions['column'], $sorterConditions['side']) ->get() ->toArray();
将 $filters 和 $sorters 传递到您的视图中,并轻松渲染它们。
<form method="GET" class="form-horizontal"> <!-- Should be submitted to the current page --> <?php foreach($filters as $filter): $filter = new Listem\Html\Decorators\Bootstrap3($filter); ?> <div class="form-group"> <?php echo $filter->renderLabel() ?> <?php echo $filter->renderFormElem() ?> </div> <?php endforeach; ?> <button type="reset">Reset</button> <button type="submit">Filter</button> </form> <table> <thead> <tr> <th><?php $sorters->render('title') ?></th> <th>Slug</th> <th><?php $sorters->render('content') ?></th> <!-- Or you can render parts of it, so you have more control --> <th> <a href="<?php $sorters->getLink('created_at') ?>"> <?php $sorters->getLabel('created_at') ?> <span class="<?php $sorters->sorted('created_at') ? 'up' : 'down' ?>"></span> </a> </th> </tr> </thead> ...
文档
贡献
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 了解详情。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。