Symfony CMF Routing Bundle を使用して動的ルートを作成しています (ここでは 1 つの例を使用しています)。
$route = new Route('/dynamic-url');
$route->setMethods("GET");
$route->setDefault('_controller', 'AppBundle:MyRoute:getResponse');
$routeCollection->add('my-dynamic-route', $route);
応答は、MyRouteController 内の getResponseAction() 関数からロードされます。
/**
* No annotations here, because I want the url to be dynamic from the database
*/
public function getResponseAction(Request $request) {
return $this->render('dynamic-page-template.html.twig');
}
「/dynamic-url」に移動すると、機能します。
別のコントローラーでは、次のようにこの動的ルートにリダイレクトしたいと考えています。
return $this->redirectToRoute('my-dynamic-route');
しかし、次のエラーが表示されます。
また興味深い: 「/dynamic-url」に移動すると、実際には開発バーにルート名が「my-dynamic-route」であると表示されます。
編集
すべてのルートをロードすると、動的ルート名が表示されません。
$this->get('router')->getRouteCollection();
彼らはこのリストに入れるべきだと思います。