2011-10-24 20 views
0

私はsymfonyのアプリケーションで、次のルートの設定を持っているの設定:は同じURLでsymfonyのルートが異なるHTTPメソッドとコントローラーアクション

executeConfigureexecuteCreateアクションにリンクされている
label: 
    url:   /label 
    param:  { module: label, action: configure } 
    requirements: { sf_method: get } 

label_create: 
    url:   /label 
    param:  { module: label, action: create } 
    requirements: { sf_method: post } 

。それから私は、このように構成されているフォーム:私の知る限りではPOST方法で設定したルートは、それを避けるとexecuteCreateを実行しなければならないが、フォームがexecuteConfigureを提出されるたび

<form action="<?php echo url_for('@label_create') ?>" method="POST"> 
    <?php echo $form->renderHiddenFields() ?> 
    <input type="hidden" name="sf_method" value="post" /> 
    <!-- more stuff here --> 
</form> 

は、実行されます。

同じURLを保持するこれらの2つのアクションを区別するにはどうすればよいですか?

ありがとうございます!

答えて

6

私もこの問題を抱え、古いフォーラムメッセージ(http://oldforum.symfony-project.org/index.php/t/25750/)で答えを見つけました。

リクエストメソッドを完全に無視している場合は、通常のsfRouteを使用する可能性が最も高いです。 sfRequestRouteを使用して、ルーティングを「メソッド対応」にする必要があります。だから、あなたの例では、あなたが行います:あなたは、コールユーザーまたはユーザーのいずれかできるURLを呼び出すときにGETだけのユーザーのために/そして

users_create: 
    pattern: /
    defaults: { _controller: "RentalAPIBundle:User:create" } 
    requirements: { _method: post } 

users:  
    pattern: / 
    defaults: { _controller: "RentalAPIBundle:User:index" }  
    requirements: { _method: get } 

label: 
    url:   /label 
    class:  sfRequestRoute 
    param:  { module: label, action: configure } 
    requirements: { sf_method: get } 

label_create: 
    url:   /label 
    class:  sfRequestRoute 
    param:  { module: label, action: create } 
    requirements: { sf_method: post } 
+1

この回答はSymfonyの古いバージョンには役立ちますが、現在のリリースでは非推奨です。どのような選択肢がありますか? –

0

を、私はこのルーティングshemeを使用して、それを解決しました/ POSTのために。理由はわかりませんが動作します

関連する問題