The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Rendering inside a group

Slimmy's Avatar

Slimmy

05 Aug, 2015 11:35 PM

Hi,

i'm using this for the cart handling:

$app->group('/cart', function () use ($app)

    {

        $app->get('/', function () use ($app)

            {

                // show cart
                $app->render('cart.php', array('title' => "Cart"));
                
            });

        $app->post('/', function () use ($app)
        
            {

                // add product to cart
                $app->render('cart.php', array('title' => "Cart"));

            });

        $app->get('/remove/:product', function ($product) use ($app)
        
            {

                // remove product from cart
                $app->render('cart.php', array('title' => "Cart"));

            });

    });

As you can see it renders the cart 3 times = redundant

So my idea was to do the only the tasks inside the 3 routings and do a render at the end:

$app->group('/cart', function () use ($app)

    {

        $app->post('/', function () use ($app)
        
            {

                // add product to cart

            });

        $app->get('/remove/:product', function ($product) use ($app)
        
            {

                // remove product from cart

            });

        $app->render('cart.php', array('title' => "Cart"));

    });

But this doesn't work and includes the whole page 2 times or something :-(

So is there a better solution than my first code?

Thanks!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac