Skip to content

Console table helper #2473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/console/helpers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The Console Helpers
dialoghelper
formatterhelper
progresshelper
tablehelper

The Console Components comes with some useful helpers. These helpers contain
function to ease some common tasks.
Expand Down
1 change: 1 addition & 0 deletions components/console/helpers/map.rst.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* :doc:`/components/console/helpers/dialoghelper`
* :doc:`/components/console/helpers/formatterhelper`
* :doc:`/components/console/helpers/progresshelper`
* :doc:`/components/console/helpers/tablehelper`
55 changes: 55 additions & 0 deletions components/console/helpers/tablehelper.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.. index::
single: Console Helpers; Table Helper

Table Helper
============

.. versionadded:: 2.3
The ``table`` helper was added in Symfony 2.3.

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

.. image:: /images/components/console/table.png

To display table, use the :class:`Symfony\\Component\\Console\\Helper\\TableHelper`,
set headers, rows and render::

$table = $app->getHelperSet()->get('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);

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

Table helper is shipped with two preconfigured table layouts:

* ``TableHelper::LAYOUT_DEFAULT``

* ``TableHelper::LAYOUT_BORDERLESS``

Layout can be set using :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setLayout` method.

Customize Table Layout using Rendering Options
----------------------------------------------

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

* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setPaddingChar`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setHorizontalBorderChar`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setVerticalBorderChar`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setVrossingChar`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setVellHeaderFormat`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setVellRowFormat`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setBorderFormat`
* :method:`Symfony\\Component\\Console\\Helper\\TableHelper::setPadType`
Binary file added images/components/console/table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.