将SLIM PHP与控制器一起使用。
希望将产品数组发布到结帐视图。
我的路线
$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()函数
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/');
}
获取结帐/索引功能(希望将产品数组传递到此处)
public function index() {
$title = "Checkout | Shop";
$this->render('shop/checkout/index.html', array("products" => $products, "title" => $title));
}