21 Oct 2019

feedSymfony Blog

New in Symfony 4.4: Horizontal Tables and Definition Lists in Console Commands

Grégoire Pineau

Contributed by
Grégoire Pineau
in #32742.

The Console component includes some features to output tables and configure them in many different ways. In Symfony 4.4 we've improved it with new types of tables.

Horizontal Tables

Consider the following table:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
// ...

class SomeCommand extends Command
{
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $table = new Table($output);
        $table
            ->setHeaders(['ISBN', 'Title', 'Author'])
            ->setRows([
                ['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'],
            ])
        ;
        $table->render();
    }
}

This is displayed as:

1
2
3
4
5
6
7
8
+---------------+--------------------------+------------------+
| 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  |
+---------------+--------------------------+------------------+

If you call to the new setHorizontal(bool $horizontal = true) method, the table is transformed into an "horizontal table", where the data is displayed in rows instead of columns:

1
2
3
4
5
6
7
$table
    ->setHeaders(['ISBN', 'Title', 'Author'])
    ->setRows([
        // ... the rows ...
    ])
    ->setHorizontal()
;
1
2
3
4
5
+--------+-----------------+----------------------+-----------------------+--------------------------+
| ISBN   | 99921-58-10-7   | 9971-5-0210-0        | 960-425-059-0         | 80-902734-1-6            |
| Title  | Divine Comedy   | A Tale of Two Cities | The Lord of the Rings | And Then There Were None |
| Author | Dante Alighieri | Charles Dickens      | J. R. R. Tolkien      | Agatha Christie          |
+--------+-----------------+----------------------+-----------------------+--------------------------+

When using the Symfony style for commands you can also use the horizontalTable() shortcut:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
use Symfony\Component\Console\Style\SymfonyStyle;

protected function execute(InputInterface $input, OutputInterface $output)
{
    $io = new SymfonyStyle($input, $output);
    $io->horizontalTable(
        ['ISBN', 'Title', 'Author'],
        [
            // ... the rows ...
        ]
    );
}

Definition Lists

In Symfony 4.4 we've also added support for "definition lists", which are a set of key-value pairs, similar to HTML's <dl>. Symfony's definition lists are more flexible because they can include titles, separators, etc.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
use Symfony\Component\Console\Helper\TableSeparator;

$io->definitionList(
    ['Version' => '4.4.0'],
    ['Long-Term Support' => 'Yes'],
    new TableSeparator(),
    'Timeline',
    ['End of maintenance' => '11/2022'],
    ['End of life' => '11/2023']
);

This example is output as follows:

1
2
3
4
5
6
7
8
-------------------- ---------
 Version              4.4.0
 Long-Term Support    Yes
-------------------- ---------
 TIMELINE
 End of maintenance   11/2022
 End of life          11/2023
-------------------- ---------

Be trained by Symfony experts - 2019-10-21 Lyon - 2019-10-28 Berlin - 2019-10-28 Berlin

21 Oct 2019 10:31am GMT

20 Oct 2019

feedSymfony Blog

A Week of Symfony #668 (14-20 October 2019)

This week, the upcoming Symfony 4.4. version added a new feature for lazy computation of string values injected into services and continued working on the new feature to store secrets. Finally, the SymfonyCon Amsterdam 2019 conference announced a fundraising for its scholarship program.

Symfony development highlights

This week, 62 pull requests were merged (26 in code and 36 in docs) and 36 issues were closed (25 in code and 11 in docs). Excluding merges, 34 authors made 1,476 additions and 444 deletions. See details for code and docs.

3.4 changelog:

4.3 changelog:

4.4 changelog:

Master changelog:

Newest issues and pull requests

They talked about us

Call to Action


Be trained by Symfony experts - 2019-10-21 Lyon - 2019-10-28 Berlin - 2019-10-28 Berlin

20 Oct 2019 7:52am GMT

18 Oct 2019

feedSymfony Blog

New in Symfony 4.4: Improved Welcome Page

Yonel Ceruto

Contributed by
Yonel Ceruto
in #33189.

When you browse a newly created Symfony project, you see a special "Welcome page" that looks like this:

The Symfony Welcome Page in Symfony 4.3 and earlier versions

Although this is an error page (you are seeing that page because you haven't configured any URL yet) we designed it to make it look more friendly than a traditional error page, specially for newcomers.

This page confirms you that Symfony was successfully installed, shows the directory of your application and provides a link to the most essential documentation for newcomers: How to create your first page in Symfony.

Even if this page is correct, its design was dull and uninspiring. That's why we decided to redesign it for Symfony 4.4/5.0. This is how the same page looks now:

The Symfony Welcome Page in Symfony 4.4 and newer versions

In addition to having a much better design, the page now provides more links to useful resources. Also, the main page color will randomly change each time you load the page, so keep reloading until the color matches your preferences.


Be trained by Symfony experts - 2019-10-21 Lyon - 2019-10-28 Berlin - 2019-10-28 Berlin

18 Oct 2019 8:07am GMT