September 25, 2018 Javier Eguiluz

Using tables to display tabular contents in console commands are one of the most popular features of the Console component. In Symfony 4.2 we improved them with new features to display titles and set their maximum column width.

Adding titles to tables¶ Contributed by

Dany Maillard

in #26933. In Symfony 4.2 tables can now display a title both at the top and the bottom of its contents with the setHeaderTitle() and setFooterTitle() methods, which is ideal for complex or paginated tables: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 use Symfony\Component\Console\Helper\Table ; // ... $table = new Table ( $output ); $table -> setHeaderTitle ( 'Books' ) -> setFooterTitle ( 'Page 1/2' ) -> setHeaders ([ 'ISBN' , 'Title' , 'Author' ]) -> setRows ([ [ '99921-58-10-7' , 'Divine Comedy' , 'Dante Alighieri' ], // ... ]) ; $table -> render (); This is how the above example would look in your terminal: 1 2 3 4 5 6 7 8 +---------------+----------- Books --------+------------------+ | ISBN | Title | Author | +---------------+--------------------------+------------------+ | 99921-58-10-7 | Divine Comedy | Dante Alighieri | | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | | 80-902734-1-6 | And Then There Were None | Agatha Christie | +---------------+--------- Page 1/2 -------+------------------+