Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Default Routing Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Resources/config/routing.yml in the bundle — this shows the route patterns the bundle registers.
  2. Routing/ and DependencyInjection/ — the loader and configuration keys.
  3. The bundle README for the exact service names and Twig helpers.

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:

  • Implicit controller routing (Route::controller('blog', 'BlogController')) for the default routing.
  • Laravel's view-name conventions and View::make('blog.list') for default templating.
  • url()->current() / relative URL helpers for the relative routing helpers.

Implementation Patterns

Convention-based controller routing

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.

Default templating

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:

  • Name templates exactly as the convention expects.
  • Override the template only when the action needs a different layout or a partial response.
  • Return a 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.

Relative routing

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.

Integration tips

  • Import the default routing last. A catch-all route in the middle of your routing file will swallow requests intended for explicit routes.
  • Combine with annotations for the important routes and default routing for simple pages. Do not try to express every route through conventions.
  • Add access_control entries for URL prefixes handled by default routing. Default routing makes it easy to expose a controller action accidentally.
  • Clear the router cache after changing route configuration: php app/console cache:clear and php app/console router:debug.
  • If you are porting the idea to Laravel, implement it as a fallback route at the bottom of 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.

Gotchas and Tips

  • This is abandoned Symfony2 code. Last release was 2016, dependents are zero, and Symfony2 is end-of-life. Do not introduce it into a new project. Use it only to understand or maintain an existing legacy application, and plan a migration to explicit Symfony routes or Laravel routes.
  • PHP and Symfony version constraints. The bundle predates PHP 7.2+ and Symfony 4/5. Expect Composer conflicts with modern symfony/* packages. If you must run it, pin your platform PHP version and test on the exact legacy stack.
  • Route shadowing is the most common failure. If a request hits the default controller instead of your intended action, check the order of imports in routing.yml. Run php app/console router:match /your/url to see which route matched and which _controller was resolved.
  • Default templating can mask missing templates. When the bundle infers a template name and the template does not exist, the error can look like a routing problem. Check the profiler's request panel for the resolved _controller and template.
  • Security exposure. Default routing makes controller actions reachable by URL without an explicit route declaration. Audit 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.
  • Relative routing in sub-requests, ESI, and CLI. Relative URL generation depends on the current request context. It is unreliable in console commands, background workers, and some sub-request/ESI scenarios. Use absolute route generation there.
  • Caching quirks. Symfony2 caches the router aggressively. After changing bundle routing or configuration, run cache:clear; in debug mode, also check app/cache/dev/appDevDebugProjectContainer.xml if the router service looks stale.
  • Extension points. If you need to customize behavior, look at decorating the router service or overriding the bundle's routing loader rather than forking the bundle. In a legacy app, a small custom route loader that wraps the default behavior is usually safer than editing vendor code.
  • Debugging checklist: 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.
  • Migration advice: if you are modernizing, replace default routing with explicit route definitions or attributes, and replace default templating with explicit render() calls. The explicitness costs a few lines per action but removes the “magic” that makes legacy debugging slow.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log