Symfony:在实时/生产服务器上不起作用“ RedirectResponse”

时间:2019-04-03 10:50:24

标签: php symfony ssl nginx

我在实时服务器上测试了我的应用程序,并收到一个错误:在控制器中完成“动作”后,他不会将我重定向到另一条路线。该错误可能来自SSL(cloudflare)或Nginx,因为在开发人员/本地服务器上工作正常

我的代码:

->操作:

public function addAction(Request $request)
{
    $cookies = $request->cookies;
    $cart = $cookies->get('SHOP_CART');

    $post_id = $request->request->get('id');
    $r = $this->getDoctrine()->getRepository('AppBundle:Product');
    $product = $r->find($post_id);

    if ($cart == null) {
        $cart = [
            'items' => [$product->getId()],
            'price' => $product->getPriceUah(),
            'count_items' => 1,
        ];
    } else {
        $cart = unserialize($cart);
        if (in_array($product->getId(), $cart['items']) === false) {
            array_push($cart['items'], $product->getId());

            $cart = [
                'items' => $cart['items'],
                'price' => $cart['price'] + $product->getPriceUah(),
                'count_items' => $cart['count_items'] + 1,
            ];
        }
    }

    $cart = new Cookie(
        'SHOP_CART',    // Имя.
        serialize($cart),    // Значение.
        time() + (31 * 24 * 60 * 60)  // Время жизни куки 1 месяц.
    );

    $res = new Response();
    $res->headers->setCookie($cart);
    $res->send();

    return new RedirectResponse($this->generateUrl('client_index_product_page', ['id' => $product->getId()]));
}

->路由:

client_cart_add:
   path:  /cart/add
   methods: [POST]
   defaults: { _controller: AppBundle:Client/Component/CartActions:add, _locale: ru }
   requirements:
       _locale: ru|ua
   options:
       expose: true

我做了另一个可行的变体,但在实时/生产中仍然无法正常工作:

        $request->getSession()
        ->getFlashBag()
        ->add('notice', 'success');

    return $this->redirect($request->headers->get('referer'));

0 个答案:

没有答案