Skip to content

Commit

Permalink
Wrap the table creation inside the class extending Command, so users …
Browse files Browse the repository at this point in the history
…know where the comes. They can use it as standalone when needed
  • Loading branch information
harikt authored and xabbuh committed Jun 28, 2015
1 parent 9dafd45 commit 00e6d3e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions components/console/helpers/table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ To display a table, use :class:`Symfony\\Component\\Console\\Helper\\Table`,
set the headers, set the rows and then render the table::

use Symfony\Component\Console\Helper\Table;

$table = new Table($output);
$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();
// ...

class SomeCommand extends Command
{
public function execute(InputInterface $input, OutputInterface $output)
{
$table = new Table($output);
$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();
}
}

You can add a table separator anywhere in the output by passing an instance of
:class:`Symfony\\Component\\Console\\Helper\\TableSeparator` as a row::
Expand Down

0 comments on commit 00e6d3e

Please sign in to comment.