2017-09-25 12 views
1

URLに(redirectToRouteで)いくつかのパラメータを同時に送信したいです(URLはレンダリングあり)。どのようにできるのか ? Symfony - URLの有無にかかわらずパラメータを同時に送信する

は例を表示するには:

AはURLであることが必要であるA及びB::私は2つのVARを持ってhttp://website.com?A=smth BはTWIGを完了するために送信する必要があります(ただし、URLによって)

それを行うコードの例を私に見せてもらえますか?

おかげ

+0

またはhttps://stackoverflow.com/questions/11227975/symfony-2-redirect-using-post/31031986#31031986 – LBA

答えて

0

ニースと簡単に、ちょうどrender()方法にキー/値の配列を渡す:

$template = $twig->load('index.html'); 
echo $template->render(array('the' => 'variables', 'go' => 'here')); 

https://twig.symfony.com/doc/2.x/api.html#rendering-templates

+0

このアプローチを使用して、私は@Destunkをレンダリングするために変数を渡すしたいとは思わないけど'redirectToRoute'が質問に記載されているので、リダイレクトを介してそれらを格納/取得します。 – nifr

1

HTTPは3xxのリダイレクトがませので、本体を持っていませんrenderでデータを含めることはできず、同時にredirectToRoute('redirect_target_route', array('A' => 'smth'})を使用することはできません。

セッションのフラッシュバックにデータを保存し、redirect_target_routeのコントローラーアクション内に保存する必要があります。

public function redirectingAction(Request $request) 
{ 
    // ... 
    // store the variable in the flashbag named 'parameters' with key 'B' 
    $request->getSession()->getFlashBag('parameters')->add('B', 'smth_else'); 

    // redirect to uri?A=smth 
    return $this->redirectToRoute('redirect_target_route', array('A' => 'smth'}); 
} 

public function redirectTargetAction(Request $request) 
{ 
    $parameterB = $request->getSession()->getFlashBag('parameters')->get('B'); 
    // ... 
} 
関連する問題