leaseweb/default-routing-bundle
LeaseWeb DefaultRoutingBundle provides a sensible default routing setup for Symfony applications, using conventions and reusable route definitions to reduce boilerplate, keep controller routes consistent, and simplify routing configuration across PHP projects.
This is a Symfony2 bundle, not a Laravel package. You cannot composer require it into a Laravel application and expect it to work; treat it as a reference implementation for convention-based routing and default view resolution. If you are maintaining a legacy Symfony 2.x app, install it with:
composer require leaseweb/default-routing-bundle
Enable the bundle in app/AppKernel.php:
$bundles = [
// ...
new Lsw\DefaultRoutingBundle\LswDefaultRoutingBundle(),
];
Import its routing as the last entry in app/config/routing.yml so the catch-all/default routes do not shadow your explicit routes:
# app/config/routing.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
lsw_default_routing:
resource: "@LswDefaultRoutingBundle/Resources/config/routing.yml"
Where to look first:
Resources/config/routing.yml in the bundle — this shows the route patterns the bundle registers.Routing/ and DependencyInjection/ — the loader and configuration keys.First use case: replace a pile of near-identical route definitions for simple controller/action pages. Instead of declaring /blog/list, /blog/show, /blog/edit, you let the default route map /{controller}/{action} to BlogController::listAction, BlogController::showAction, etc., and let the bundle render Blog/list.html.twig when the controller does not return a Response.
For a Laravel developer, the closest analogues are:
Route::controller('blog', 'BlogController')) for the default routing.View::make('blog.list') for default templating.url()->current() / relative URL helpers for the relative routing helpers.The core workflow is to define a controller and let the URL determine the action. A request to /blog/list resolves to BlogController::listAction; /blog/show/42 resolves to BlogController::showAction with id = 42. This is useful for admin panels, CRUD screens, and internal tools where the URL structure mirrors the controller structure.
// src/AppBundle/Controller/BlogController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class BlogController extends Controller
{
public function listAction()
{
$posts = $this->getDoctrine()->getRepository('AppBundle:Post')->findAll();
return $this->render('AppBundle:Blog:list.html.twig', ['posts' => $posts]);
}
public function showAction($id)
{
$post = $this->getDoctrine()->getRepository('AppBundle:Post')->find($id);
return $this->render('AppBundle:Blog:show.html.twig', ['post' => $post]);
}
}
Keep explicit routes for anything security-sensitive, anything with a non-obvious URL, and anything that needs HTTP-method restrictions. Use the default routing for the long tail of simple pages.
The bundle's default templating behavior removes boilerplate return $this->render(...) calls. Instead of naming the template in every action, the bundle can infer Bundle:Controller:action.html.twig from the route. This is the Symfony2 equivalent of Laravel returning a view by convention.
Practical pattern:
Response when you do not want the default template rendered; return an array or null when you do.public function listAction()
{
return ['posts' => $this->getDoctrine()->getRepository('AppBundle:Post')->findAll()];
// renders AppBundle:Blog:list.html.twig by convention
}
This works best when your template directory mirrors your controller directory. If you have irregular naming, keep explicit render() calls; the convention will fight you otherwise.
Use relative routing helpers when generating links that should stay within the current section of the site: pagination links, tab navigation, sort toggles, and “back to list” links. Instead of hard-coding a route name or rebuilding the current URL query string by hand, generate a path relative to the current request.
Typical Twig usage:
<a href="{{ relative_path('page', { page: posts.previousPage }) }}">Previous</a>
<a href="{{ relative_path('page', { page: posts.nextPage }) }}">Next</a>
<a href="{{ relative_path('sort', { sort: 'createdAt', direction: 'desc' }) }}">Newest first</a>
In PHP:
$url = $this->get('lsw_default_routing.relative_router')
->generateRelativePath('page', ['page' => 2]);
This is useful when you have a generic listing page reachable from multiple parent routes and you do not want to hard-code the parent route name. Treat it as a convenience, not a replacement for explicit route generation in emails, CLI commands, or cross-section links.
access_control entries for URL prefixes handled by default routing. Default routing makes it easy to expose a controller action accidentally.php app/console cache:clear and php app/console router:debug.routes/web.php, plus a view composer or controller base class that resolves the template from the route action name. Do not attempt to install the Symfony bundle itself.symfony/* packages. If you must run it, pin your platform PHP version and test on the exact legacy stack.routing.yml. Run php app/console router:match /your/url to see which route matched and which _controller was resolved._controller and template.access_control, firewalls, and controller method visibility after enabling it. In Laravel terms, this is the same risk as Route::controller() exposing every public method.cache:clear; in debug mode, also check app/cache/dev/appDevDebugProjectContainer.xml if the router service looks stale.router:debug for the route table, router:match for a specific URL, the Symfony profiler for the resolved controller and template, and the dev.log for routing exceptions. If the wrong action runs, it is almost always route order or a missing explicit route.render() calls. The explicitness costs a few lines per action but removes the “magic” that makes legacy debugging slow.How can I help you explore Laravel packages today?