Symfony template locations: questioning the best practice

A while ago the Symfony project published a “Best Practices” book.

This is a source of excellent suggestions and it’s written by the people who wrote Symfony in the first place, so we decided to stick to it as much as possible, even in those few cases where the benefits where not immediately clear.

But after a few more Symfony projects, there is one best practice that I definitely want to question: the location of the templates.

Continue reading Symfony template locations: questioning the best practice

Symfony and Monolog: define a custom logger file at runtime

I had the need to write to  a custom log file, but with the additional constraint that the file name was not known until runtime (UUID for a new entity).

On the Symfony Cookbook there is already a recipe about using different log files but it relies on a configuration made before the execution.

After a little experimenting, here’s the simple solution I implemented:

use Symfony\Bridge\Monolog\Logger;
use Monolog\Handler\StreamHandler;
// ...
$logger = new Logger('import');
$logger->pushHandler(new StreamHandler($kernelRootDir . '/logs/' . $runtimeGeneratedId.'.import.log', Logger::DEBUG));

Symfony assets management: assets:install

In your Symfony application there are bound to exist many assets (JS, CSS, and so on) either created by you or provided by third-party bundles.

As part of your deploy procedure, you usually have to use some Symfony console command to actually make the assets available to the frontend of your application.

Let’s start with the most basic solution: the assets:install command.

Continue reading Symfony assets management: assets:install