jgm/tablebundle

此包已被废弃,不再维护。未建议替代包。

用于为 symfony 应用创建数据表的包。

安装次数: 3,503

依赖者: 0

建议者: 0

安全: 0

星标: 8

关注者: 3

分支: 8

开放问题: 7

类型:symfony-bundle

v1.3.3 2016-08-18 11:54 UTC

README

JGM TableBundle 是用于构建 PHP 中的数据表并在 twig 中轻松渲染的 Symfony 框架(Symfony2 或更高版本)的包。

为什么我应该使用此包?

创建数据表是一项枯燥而繁琐的工作。您必须关注渲染、分页、排序和筛选给定的数据。有时,您还想重用您的表格。

使用 TableBundle 将是您问题的答案。它提供了构建表格的功能,包括动态列,用于显示来自不同来源(如数据库中的实体或数组)的数据。此外,TableBundle 还支持动态筛选、分页和排序的机制。您无需关心实现,一切都是自动的。

一个独特的功能是自动连接,允许您访问并筛选给定数据的连接列(以及它们的连接列,以及它们的...)。

安装

使用 composer

  1. 通过执行命令 composer require jgm/tablebundle 或将行 "jgm/tablebundle": "1.3.*" 添加到 required-部分来将包添加到您的 composer.json

  2. 将 Bundle 添加到您的 Kernel (app/AppKernel.php)

// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...,
            new JGM\TableBundle\JGMTableBundle()
        );
        // ...
    }
    // ...
}

依赖

  • php: >=5.3.9
  • symfony/symfony: >=2.5
  • symfony/config: >=2.5
  • symfony/yaml: >=2.5
  • symfony/security: >=2.5
  • symfony/templating: >=2.5
  • symfony/http-foundation: >=2.5
  • symfony/http-kernel: >=2.5
  • symfony/dependency-injection: >=2.5
  • doctrine/common: >=2.3

基本用法

步骤 1:创建一个表格类型

// src/YourBundle/Table/Type/StudentTableType.php
class StudentTableType extends JGM\TableBundle\Table\Type\AbstractTableType
{
    public function buildTable(TableBuilder $builder) 
    {
		$builder
			->add('text', 'name', ['label' => 'Name'])
			->add('number', 'term', ['label' => 'Term'])
			->add('date', 'birthday', ['label' => 'Day of birth']);
    }

    public function getDataSource(ContainerInterface $container)
    {
      return new EntityDataSource('YourBundle:Student');
    }

    public function getName()
    {
        return 'student_table';
    }

    public function configureOptions(OptionsResolver $resolver)
    {
		$optionsResolver->setDefaults(array(
			'attr' => array('width' => '600px', 'class' => 'table-css'),
			'empty_value' => 'There is no student...'
		));
    }
}

步骤 2:实例化表格

// src/YourBundle/Controller/StudentController.php
<?
class StudentController extends Symfony\Bundle\FrameworkBundle\Controller\Controller
{
    public function showAction()
    {
        $table = $this->get('jgm.table')->createTable(new StudentTableType());
		return array('studentTable' => $table->createView());
    }
}

步骤 3:在 twig 模板中渲染表格

<h1>Students</h1>
{{ table(studentTable) }}

文档

有关更多信息,请参阅 文档网站