soluble/flexstore

0.13.1 2019-04-14 21:20 UTC

README

PHP Version Build Status Code Coverage Scrutinizer Quality Score Latest Stable Version Total Downloads License

简介

特性

  • 可扩展的数据源
  • ColumnModel变更
  • 渲染器和格式化程序
  • 自定义写入器

需求

  • PHP引擎5.6+, 7.0+

文档

安装

通过composer快速安装。

$ composer require soluble/flexstore

大多数现代框架都内置了Composer,但请确保包含以下文件

<?php
// include the Composer autoloader
require 'vendor/autoload.php';

快速开始

API

获取存储库

从zend-db选择获取存储库。

<?php

use Soluble\FlexStore\Store;
use Soluble\FlexStore\Source;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Select;

// 1. Database adapter

$adapter = new Adapter([
                'driver'    => 'mysqli',  // or PDO_Mysql
                'hostname'  => $hostname,
                'username'  => $username,
                'password'  => $password,
                'database'  => $database,
                'charset'   => 'UTF-8'
]);

// 2. Make a select

$select = new Select();
$select->from('product')
       ->where(['flag_archive' => 0]);

// 3. Create a datasource
$sqlSource = new Source\Zend\SqlSource($adapter, $select);

// 4. Get a Store
$store = new Store($sqlSource);

在存储库中检索数据

<?php

use Soluble\FlexStore\Store;
use Soluble\FlexStore\Options;

// 4. Get a Store
$store = new Store($sqlSource);


$options = new Options();
$options->setLimit(10);

$data = $store->getData($options);

foreach ($data as $idx => $row) {
    // The $row is an ArrayObject
    echo $idx . '-' . $row['column'] . PHP_EOL;
}

获取ColumnModel

<?php

use Soluble\FlexStore\Store;
use Soluble\FlexStore\Options;

// 4. Get a Store
$store = new Store($sqlSource);


$cm = $store->getColumnModel();

$columns = $cm->getColumns();

// Will look like
[
 ["col_1_name"] => (Soluble\FlexStore\Column\Column) 
 ["col_2_name"] => (Soluble\FlexStore\Column\Column) 
]

// Getting information about a column

$column = $cm->getColumn("col_1_name");

$properties = $column->getProperties();

$column->getName();
$column->getHeader();
$column->getType();

$column->getFormatter();

$column->getWidth();
$column->isEditable();
$column->isExcluded();
$column->isFilterable();
$column->isGroupable();
$column->isSortable();

API

存储库

Soluble\FlexStore\Store

选项

Soluble\FlexStore\Options可用于修改数据检索过程。

结果集

Store::getData()方法返回一个实现Resultset\ResultsetInterface的结果集。此接口是可遍历的、可计数的,并实现了Iterator接口(foreach...)

ColumnModel

ColumnModel允许更改列的检索或显示方式。

必须在调用Store::getData()方法之前调用。

基本信息

排序列

更改检索列的顺序。

获取或设置排除项

被排除的列不会被Store::getData()方法检索。

添加虚拟列

添加一个在底层源中不存在的列。此列的值通常由渲染器计算。

搜索列

您可以在ColumnModel中搜索匹配特定模式的列。

元数据

元数据目前是自动检索的(这可能会改变...)

在ColumnModel上搜索

您可以在ColumnModel中搜索匹配特定模式的列,并对结果应用操作。

使用关联的Search\Result,您可以轻松地

在ColumnModel上搜索

您可以在ColumnModel中搜索匹配特定模式的列,并对结果应用操作。

支持的驱动程序

贡献

欢迎贡献,请参阅贡献指南

编码标准