devrtips / listr
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: 2022-02-01 12:52:09 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)。请参阅许可文件以获取更多信息。