Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Components
  4. Console
  5. Helpers
  6. Table Helper
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • Customize Table Layout using Named Layouts
  • Customize Table Layout using Rendering Options

Table Helper

Edit this page

Warning: You are browsing the documentation for Symfony 2.7, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

Table Helper

2.3

The table helper was introduced in Symfony 2.3.

Caution

The Table Helper was deprecated in Symfony 2.5 and will be removed in Symfony 3.0. You should now use the Table class instead which is more powerful.

When building a console application it may be useful to display tabular data:

To display a table, use the TableHelper, set headers, rows and render:

1
2
3
4
5
6
7
8
9
10
11
$table = $this->getHelper('table');
$table
    ->setHeaders(array('ISBN', 'Title', 'Author'))
    ->setRows(array(
        array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
        array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'),
        array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
        array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
    ))
;
$table->render($output);

The table layout can be customized as well. There are two ways to customize table rendering: using named layouts or by customizing rendering options.

Customize Table Layout using Named Layouts

The Table helper ships with three preconfigured table layouts:

  • TableHelper::LAYOUT_DEFAULT
  • TableHelper::LAYOUT_BORDERLESS
  • TableHelper::LAYOUT_COMPACT

Layout can be set using setLayout() method.

Customize Table Layout using Rendering Options

You can also control table rendering by setting custom rendering option values:

  • setPaddingChar()
  • setHorizontalBorderChar()
  • setVerticalBorderChar()
  • setCrossingChar()
  • setCellHeaderFormat()
  • setCellRowFormat()
  • setBorderFormat()
  • setPadType()
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Save your teams and projects before they sink

Save your teams and projects before they sink

Measure & Improve Symfony Code Performance

Measure & Improve Symfony Code Performance

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Sebastian Busch, a Symfony contributor

Thanks Sebastian Busch (@sebu) for being a Symfony contributor

1 commit • 2 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia