Symfony2:路由优先级 [英] Symfony2: Routing priority

查看:34
本文介绍了Symfony2:路由优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要在 Symfony2 中对路由进行优先级排序?

is there anyway to prioritize routes in Symfony2?

我正在使用注释,它看起来像这样

i'm using annotation it looks like this

控制器

//TestController.php

/**
 * @Route("/test")
 */
class TestController extends Controller
{
    /**
     * @Route("/a", name="test_a")
     */
   .....

//DummyController.php
/**
 * @Route("/")
 */
class DummyController extends Controller
{
    /**
      * @Route("/{varA}/{varB}", name="dummy_one")
      */
   .....

配置

//routing.yml

acme_bundle:
    resource: "@Acme/Controller"
    type:     annotation

目标

URL      , Actual              , Goal
/test/a  , DummyController     , TestController  //Wrong
/test/b  , DummyController     , DummyController //Good

如何强制首先测试 TestController?

How can i force TestController to be tested first ?

谢谢

推荐答案

所以 Symfony 会按照字母顺序使用控制器,并且会一一添加路由.

So Symfony will consume the controllers in an alphabetical order and will add the routes one by one.

如果不为 当前版本 2.5 使用另一个包,目前无法增加优先级

there is no way up to add priority at the moment without using another bundle for that currently version 2.5

https://github.com/symfony-cmf/Routing 是一个很好的包,如果您正在寻找高级路由.

https://github.com/symfony-cmf/Routing is a great bundle if you are looking for advanced routing.

这篇关于Symfony2:路由优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆