0

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));

    }
Zack1101
  • 107
  • 1
  • 10
  • Okey, and the question is exactly what? – Adam May 30 '16 at 08:26
  • I'm looking to POST the $product array to the /checkout/ View, so I can loop around the $product array. Can I pass an array through the redirect $this->app->response->redirect('/shop/checkout/'); into the checkout/view so I can render that in $this->render('shop/checkout/index.html'); – Zack1101 May 30 '16 at 13:57
  • Please check at http://stackoverflow.com/questions/30970089/slim-framework-redirect-with-params – Hitesh P May 31 '16 at 09:40

0 Answers0