1

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();

彼らはこのリストに入れるべきだと思います。

4

3 に答える 3

0

I started to think about this and pointed your question to an routing issue on symfony-cmf. You tagged with #symfony-cmf and i think this would be important feature for us.

I also think, when you persist your route with /my-route you should also ask the router for that name (or in case of the CMF with an content object with that a route.)

于 2017-07-20T15:28:56.003 に答える