2011-05-12 65 views
1

我有一個頁面,其URI是/importBundle/96/iTunes,其中96是導入包的ID。當我在瀏覽器中導航到此頁面時,它工作得很好。然而,當我提交表單(它提交回相同的頁面)時,我得到「Action」importBundle/96「不存在」,這是絕對正確的,但這不是我要告訴它去的地方。當我收到這個錯誤時,我仍然在地址欄中看到/importBundle/96/iTunessymfony路由似乎與GET一起使用但不是POST

任何想法,爲什麼這可能是這種情況?

(我在的symfony 1.4)

編輯:這裏就是我有我的routing.yml:

import_bundle: 
    class: sfDoctrineRouteCollection 
    options: 
    model:    ImportBundle 
    module:    importBundle 
    prefix_path:   /importBundle 
    column:    id 
    with_wildcard_routes: true 

這是我的開放<form>標籤:

<form action="<?php echo url_for('importBundle/iTunes?id='.$import_bundle->getId()) ?>" method="post" enctype="multipart/form-data"> 

編輯2:以下是我試圖添加的方法sf_method

import_bundle: 
    class: sfDoctrineRouteCollection 
    options: 
    model:    ImportBundle 
    module:    importBundle 
    prefix_path:   /importBundle 
    column:    id 
    with_wildcard_routes: true 
    requirements: 
    sf_method: [get,post] 

它不起作用。我做錯了嗎?我這樣做的方式似乎與the docs一致,所以我很困惑。

+2

您能向我們展示您的routing.yml文件的相應條目嗎? – greg0ire 2011-05-12 21:35:18

+0

另外,您是否可以包含您提交的

的action =「」部分。 – Tom 2011-05-12 22:04:10

+0

我加了那些東西;看我的編輯。 – 2011-05-13 13:16:40

回答

0

您可能正在使用post方法提交表單,並且所討論的路由僅針對get方法進行配置。然後,symfony回到默認的/:module /:action/*路徑,顯然找不到「importBundle/96」。

如果您發佈到同一頁面,則應該爲get和post方法配置url。

url_name: 
    requirements: 
    sf_method: [get,post] 
1

我最終只爲這一頁創建了一個全新的路由規則。不是一件非常酷的事情,但它的工作。

import_bundle_itunes: 
    class: sfDoctrineRoute 
    url:  /iTunes/:id 
    options: { model: ImportBundle, type: object } 
    param: { module: importBundle, action: iTunes } 
    requirements: 
    id: \d+ 
    sf_method: [get,post]