【问题标题】:Reference another route in your routing.yml in Symfony?在 Symfony 中的 routing.yml 中引用另一条路由?
【发布时间】:2011-02-20 07:51:04
【问题描述】:

开发一个插件,我的插件目录中有一个 routing.yml,用 sfPropelRoute 指定一个路由。

在我的 plugins/myPlugin/config/routing.yml 中:

myplugin_test:
  url:   /myurl/:id
  class:   sfPropelRoute
  options: { model: myClass, type: object, method_for_criteria: selectAvailableObj }
  params: { module: mymodule, action: show }
  requirements:
    sf_method: [GET, POST]

效果很好。

但是,在我的应用程序 (apps/myapp/config/routing.yml) 中,我想定义一个具有人类意义的绝对 URL 我想做这样的路由:

my_profile:
  url:   /my-super-profile
  class: sfRoute
  params: { route: @myplugin_test, id: 1 }

显然,我的语法不正确!

【问题讨论】:

  • 您所指的绝对网址在哪里?请注意,如果您将“absolute =>”true”参数传入,则 url_for 和 link_to 都能够从路由规则生成绝对 URL。
  • 我想要网址:myserver.com/my-super-profile
  • 我认为 mere-teresa 指的是 /my-super-profile,它应该给出与 /myurl/:id 相同的页面,其中 id 是 1。所以不是绝对的,但可能是静态 url?

标签: routing symfony1 propel


【解决方案1】:

我认为 sfRoute 中没有route 参数。

您可能希望为该特定 URL 编写一个 RewriteRule:

RewriteEngine On
RewriteRule ^/my-super-profile$ /myurl/1 [L,QSA]

【讨论】:

    【解决方案2】:

    为了记录,我改变了我的方法(避免 URL 重写),我现在使用 slug。

    在我的 plugins/myPlugin/config/routing.yml 中:

    myplugin_test:
      url:   /myurl/:slug
      class:   sfPropelRoute
      options: { model: myClass, type: object }
      params: { module: mymodule, action: show}
      requirements:
        sf_method: [GET, POST]
    

    【讨论】:

      猜你喜欢
      • 2012-01-21
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多