devrtips/listr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devrtips/listr

Composer 安装命令:

composer require devrtips/listr

包简介

Listem is an easy to use (but highly customizable) data sorting and filtering module for PHP, that can be used for data lists/tables/grids, reports or APIs.

README 文档

README

Build Status

Listem is an easy to use (but highly customizable) data sorting and filtering module for PHP >= 5.4, which can be used for data lists/tables/grids, reports or APIs.

Installation

Make sure you have Composer installed and run the below command from your project directory.

composer require listem/listem-php

General Usage

Set configurations and initialize.

$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();

Pass $filters and $sorters to your view and render them easily.

<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>

    ...

Documentation

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-19