douxunwei7083 2012-07-21 19:07
浏览 45
已采纳

Symfony 1.4路由:来自不同类的字段

How is it possible to create and match a route with fields from different classes? Is it possible? Is there any custom routing class?

For example I have these two classes:

File:
  columns:
    name: { type: string(255), unique: true, notnull: true }
    ...

Link:
  columns:
    file_id: { type: bigint, notnull: true }
    ticket: { type: string(64), notnull: true }
  relations:
    File:
      local: file_id
      foreign: id
      foreignAlias: links
  ...

Now suppose I want to create a route like this: mysite.com/:ticket/:name As you can see, ticket is a field of Link table and name is a field of File table. Is there any way to create such links in symfony 1.4?

First solution is to change the primary key of the File table and set it to it's name. I know this, but I wonder if there exist a way to handle this through routing.

My goal is when I called getObject method, it returns a Link object with sent ticket, but the existence and relationship with sent file name should also be checked.

  • 写回答

1条回答 默认 最新

  • douyimin1083 2012-07-22 08:56
    关注

    IIRC you can do something like that:

    my_route:
      url: /:ticket/:name
      class: sfDoctrineRoute
      param: { module: yourModule, action: yourAction }
      options: { type: object, model: Link, method: findLinkWithSendTicket }
    

    Then symfony should call LinkTable::findLinkWithSendTicket method and pass to it parameters, so you can use it to fetch object.

    Links can be helpful:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度