2012-07-21 92 views
0

如何創建和匹配來自不同類別的字段的路由? 這可能嗎?有沒有自定義路由類?Symfony 1.4路由:來自不同類別的字段

例如,我有以下兩類:

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 
    ... 

現在假設我要創建這樣一個路徑:mysite.com/:ticket/:name 正如你所看到的,ticketLink表和name的字段的字段File表。有什麼方法可以在symfony 1.4中創建這樣的鏈接?

第一個解決方案是更改File表的主鍵並將其設置爲它的名稱。我知道這一點,但我想知道是否有辦法通過路由來處理這個問題。

我的目標是當我調用getObject方法時,它返回一個帶有發送票據的Link對象,但是也應該檢查是否存在與已發送文件名的關係。

回答

2

IIRC你可以做這樣的事情:

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

然後symfony中應該調用LinkTable::findLinkWithSendTicket方法,並傳遞給它的參數,所以你可以用它來獲取對象。

鏈接可能會有所幫助: