Fix SoftDeletable Doctrine Entities with Unique Index Columns (Symfony2)

If you are using the Gedmo SoftDeletable Doctrine extension for entities that have some unique index columns, you will probably encounter a MySQL error when trying to add new entity with the same values as one previously deleted:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ... for key …

Find out how to avoid this by reading this post: Symfony2: Gedmo SoftDeletable Doctrine Entities with Unique Index Columns.

How to get the current route and URL in Symfony2

To get the current URL in a Symfony2 project, use the following code.

In a controller:

public function someAction(\Symfony\Component\HttpFoundation\Request $request)
{
    $route = $request->get('_route');
    $url = $request->getUri();
}

In a TWIG template:


{{ app.request.get('_route') }}

{{ app.request.getUri }}

Why would you need this? For example to setup social share buttons for the current page.