I currently live in Bizzaro World with one client.
Since the symfony application we are writing has a response entered on a page in another application, we are forced to have only one URL for the application, but, fortunately, we get the chain passed to us.
So I need to do the exact opposite of how symfony does something, a kind of old MVC approach. I need routing to work through request parameters, routing to the right controller and rendering the correct answer, rather than using a standard and reasonable path.
So the URLs will be http://www.bizzaro.com/appname?route=%2fblog , not http://www.bizzaro.com/appname/blog , etc.
The routing section has good examples of how to ensure that periods will be executed as parameters for controller actions, but not for this rather regressive approach.
Where can i start?
I implemented solution 2 proposed by Corentin Dandoy below, but slightly modified to prevent a loop when searching for a root.
namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class FrontControllerControllerController extends Controller { /** * Forward the request to the appropriate controller * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { // get the parameter that specifies the route to the 'real' homepage controller $homeroute = $this->container->getParameter('homeroute'); $route = $request->query->get('route'); // Convert the query-string route into a valid path route $path = '/'.$route; // if it is the route, then use the 'real' homepage controller, otherwise you end up in a routing loop! if ($path === '/') { $match = $this->get('router')->match('/' . $homeroute); } else { try { $match = $this->get('router')->match($path); } catch (ResourceNotFoundException $e) { throw $this->createNotFoundException('The route does not exist'); } } $params = array( 'request' => $request, ); return $this->forward($match['_controller'], $params); } }
source share