dongqieli4164 2016-05-29 12:53
浏览 36

超薄PHP - POST数组到渲染模板视图

Using SLIM PHP with Controllers.

Looking to POST an product array to the checkout View.

My Routes

$app->get('/shop/product/:slug/', array(new \Controller\ShopController(), "getProduct"));
$app->post('/shop/product/:slug/', array(new \Controller\ShopController(), "addToCheckout"));
$app->get('/shop/checkout/', array(new \Controller\CheckoutController(), "index")); 

POST addToCheckout() function

public function addToCheckout() {

    $req = $this->app->request()->post();

    $productId = $req['productId'];
    $productSize = $req['size'];
    $productQuantity = $req['quantity'];

    // pass array to /shop/checkout/ View
    $product = array(
         'id' => $productId,
         'size' => $productSize,
         'quantity' => $productQuantity
    );

    $this->app->response->redirect('/shop/checkout/');

}

GET checkout/index function (looking to pass the product array through to here)

public function index() {

        $title = "Checkout | Shop";

        $this->render('shop/checkout/index.html', array("products" => $products, "title" => $title));

    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区
    • ¥20 jupyter保存图像功能的实现
    • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
    • ¥15 NAO机器人的录音程序保存问题
    • ¥15 C#读写EXCEL文件,不同编译
    • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键