定制 andydune/html-table 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

andydune/html-table

Composer 安装命令:

composer require andydune/html-table

包简介

This code will simplify or improve your work with html tables.

关键字:

README 文档

README

This code will simplify or improve your work with html tables.

Build Status Software License Packagist Version Total Downloads

Requirements

PHP version >= 5.6

Installation

Installation using composer:

composer require andydune/html-table

Or if composer was not installed globally:

php composer.phar require andydune/html-table

Or edit your composer.json:

"require" : {
     "andydune/html-table": "^1"
}

And execute command:

php composer.phar update

Example

Here is small part of code for drawing html table with dynamic data.

<table class="table authlog">
    <thead>
    <tr>
        <td>ID</td>
        <td>User</td>
        <td>STATUS</td>
        <td>Created</td>
        <td>Updated</td>
        <td>Uploaded</td>
        <td>Link</td>
        <td>Data</td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($list as $file) {
        ?>
        <tr class="<?= $file->getStatus() == 2 ? 'table-success' : null; ?>">
            <td><?= $file->getId(); ?></td>
            <td><?= $user['EMAIL'] ?> (<?= $user['XML_ID'] ?>)</td>
            <td><?= $showStatus($file->getStatus()); ?></td>
            <td><?= $file->getData('DATETIME'); ?></td>
            <td><?= $file->getData('DATETIME_UPDATE'); ?></td>
            <td><?= $file->getData('DATETIME_LAST_REQUEST'); ?></td>
            <td><?= $file->getFileName(); ?>.<?= $file->getFileType() ?></td>
            <td><? $showArray($file->getMeta()) ?></td>
            <td></td>
            <td>повтор</td>
            <td>удаление</td>
        </tr>
    <?php } ?>
    </tbody>
</table>

It is simple to accidentally break html by removing single tag. And it is difficult to read and change.

There is better code down below:

use AndyDune\HtmlTable\Builder;
use AndyDune\HtmlTable\Table;

$table = new Table();
$head = $table->head();
$head->cell()->setContent('ID');
$head->cell()->setContent('User');
$head->cell()->setContent('STATUS');
$head->cell()->setContent('Created');
$head->cell()->setContent('Updated');
$head->cell()->setContent('Uploaded');
$head->cell()->setContent('Uploaded');
$head->cell()->setContent('Data');
// Empty cells will be added automatically depends on max cell count for next rows.
foreach ($list as $file) {
    $row = $table->row();
    if ($file->getStatus() == 2) {
        $row->addClass('table-success')
    }
    $row->cell()->setContent($file->getId());
    $row->cell()->setContent($user['EMAIL'] . $user['XML_ID']);
    $row->cell()->setContent($showStatus($file->getStatus()));
    $row->cell()->setContent($file->getData('DATETIME'));
    $row->cell()->setContent($file->getData('DATETIME_UPDATE'));
    $row->cell()->setContent($file->getData('DATETIME_LAST_REQUEST'));
    $row->cell()->setContent($file->getFileName() . '.' . $file->getFileType());
    $row->cell()->setContent($showArray($file->getMeta()));
}

$buider = new Builder($table);
$builder->setGroupingSections(true);
echo $buider->getHtml(); 

Class structure

Table structure is reflect by classes:

  • AndyDune\HtmlTable\Table - a root of the structure

  • AndyDune\HtmlTable\Element\Row - it implements a table row

  • AndyDune\HtmlTable\Element\Head - it implements a special table row (head). It can be only one.

  • AndyDune\HtmlTable\Element\Cell - it implements a table cell. It is a part of Row (Head)

  • AndyDune\HtmlTable\Builder - the root class for building html code for table. It receives Table instance as a construct parameter.

  • There are many assistive classes for building table, but you don't need to know about their.

Describe table

Table may have attributes, data rows, head row. Rows and cells may have attributes too.

Table, row, cell class attribute

Use method addClass to inject class into table element. Element may have many classes:

use AndyDune\HtmlTable\Table;

// Set classes *useful* and  *one* to table.
$table = new Table();
$table->addClass('useful')->addClass('one');
$table->getClasses(); ['useful', 'one]
// <table class="useful one">

// Set class *active* to row.
$row = $table->row();
$row->addClass('active');
// <tr class="active">

// Set class *left* to cell.
$cell = $row->cell();
$row->addClass('left');
// <td class="left">

Table, row, cell id attribute

Use method setId to inject id into table element. Element may have only one id:

use AndyDune\HtmlTable\Table;

// <table id="top">
$table = new Table();
$table->setId('top');
$table->getId(); // top

// <tr id="active">
$row = $table->row();
$row->setId('active');
$row->getId(); // active

// <td id="left">
$cell = $row->cell();
$row->setId('left');
$row->getId(); //left

andydune/html-table 适用场景与选型建议

andydune/html-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「array」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 andydune/html-table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andydune/html-table 我们能提供哪些服务?
定制开发 / 二次开发

基于 andydune/html-table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-19