开发者

symfony route seems to work with GET but not POST

I have a page whose URI is /importBundle/96/iTunes where 96 is the import bundle's id. When I navigate to this page in a browser, it works just fine. However, when I submit the form (which submits right back to the same page) I get "Action "importBundle/96" do开发者_如何学编程es not exist," which is absolutely true, but that's not where I'm telling it to go. When I get this error, I still see /importBundle/96/iTunes in the address bar.

Any idea why this could be the case?

(I'm on symfony 1.4.)

Edit: here's what I have in my routing.yml:

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

And here's my opening <form> tag:

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

Edit 2: Here's how I tried to add 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]

It doesn't work. Did I do it wrong? The way I did it seems consistent with the docs, so I'm confused.


I ended up just creating a whole new routing rule just for this one page. Not a very cool thing to have to do but it works.

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]


You are probably submitting a form with post method, and the route in question is only configured for get method. Then, symfony falls back to default /:module/:action/* route and obviously can't find "importBundle/96".

If you post to the same page, then the url should be configured both for get and post methods.

url_name:
  requirements:
    sf_method: [get,post]


You need to use the sfRequestRoute class. See the accepted answer in Configuring a route in Symfony with the same URL but different HTTP methods and controller actions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜