Symfony Routing Implementation - Libbna/CUSTOM-CMS GitHub Wiki

Symfony Routing Implementation in Custom CMS

  • Followed the basic approach listed in this document.

  • Also simultaneously went through the symfony-routing component documentation to understand the concepts being applied.

  • Symfony Routing component docs - Symfony Routing.


Adding routes in the CMS.

  • In this custom-cms, routes can be added using a two-step procedure. Go to the routes/route.php file which contains all the defined routes.
  1. Defining the routes.

    • First, you need to define the route and the controller-action associated with that route.
    • Example :- I want to add a route foo and this route should contain Home as the controller and the getData() as the action. So routing for this example will look something like this ->

$foo_route = new Route('/foo', ['controller' => "Home::getData"]);

  • We store the defined route /foo in the $foo_route variable for step two of the routing process.
  • This how we define new routes in the Custom-CMS.
  1. Adding the defined route to the routes collection.

    • In the second step we will add the newly defined route /foo to routes collection.
    • The route collection stores all the defined and valid routes of the CMS.
    • To add the defined route to the routes-collection, follow this ->

$routes->add('foo_route', $foo_route);

  • Here, we are adding the routes to the route collection and also giving it a name foo_route.
  • Now the route /foo is completely added as one of the routes of the Custom-CMS.