将数据从一个视图发送到另一个视图-流明(AMP)

时间:2018-06-27 11:30:12

标签: php routes lumen amp-html

我试图在不带Lumen控制器的情况下将数据从一个视图发送到另一个视图。该流程如下所示:

1)用户选择产品变体
2)amp-bind添加     值*(价格,名称和客户ID)*到隐藏字段
3)用户     点击“添加到购物车”
4)表单提交完成后,     routes.php获取路线上的数据"add-to-cart"
5)     路线“添加到购物车”然后使用AMP-Redirect-To,以便用户     重定向到routes.php中另一个名为"cart"的视图。     (我var_dump $ response,然后得到变量(名称,价格和     ClientId)
6)在路由"cart"中, 数据不可用     现在 。我做了var_dump($response),但一无所获,     数据丢失。代码如下:

查看:

<form id="order"
          method="POST"
          action-xhr="/amp/proteinfabrikken/add-to-cart"
          target="_top"
          class="flex flex-wrap m1">
                    <div class="items-center flex my1">
                        <input type="submit"
                               class="ampstart-btn caps"
                               name="add-to-cart"
                               value="add to cart">
                    </div>
                    <input type="hidden"
                           name="name"
                           [value]=" variationSelect.variations.filter(x => x.variation_id == selected_variation)[0].name">
                    <input type="hidden"
                           name="price"
                           [value]="variationSelect.variations.filter(x => x.variation_id == selected_variation)[0].selling_price">
                    <input name="clientId"
                           type="hidden"
                           value="CLIENT_ID(cart)"
                           data-amp-replace="CLIENT_ID">
                    <div submit-error>
                        <template type="amp-mustache">
                            Error! Looks like something went wrong with your shopping cart, please try to add an item again. {{error}}
                        </template>
                    </div>
                    </form>

Routes.php:

$app->post($prefix . '/add-to-cart', function (Request $request, Response $response) {


    $name = $request->request->get('name');
    $price = $request->request->get('price');
    $clientId = $request->request->get('clientId');


    return response()
        ->json(['name' => $name, 'price' => $price,'clientId' => $clientId])
        ->header('Content-Type', 'application/json')
        ->header('Access-Control-Allow-Credentials', 'true')
        ->header('Access-Control-Allow-Origin', '*.ampproject.org')
        ->header('AMP-Access-Control-Allow-Source-Origin', Util::getFullPath(""))
        ->header('AMP-Redirect-To', 'http://localhost:1332/amp/proteinfabrikken/cart')
        ->header('Access-Control-Expose-Headers', 'AMP-Access-Control-Allow-Source-Origin, AMP-Redirect-To');



});

$app->get($prefix . '/cart', function (Request $request, Response $response) {
    echo "<pre>";
    return var_dump($request);
});

return var_dump($request)'/cart'中为空

有人可以看到问题吗?

0 个答案:

没有答案