Hey All,

I am trying to make a simple shopping cart system and am having
trouble deleting a product from the cart.

I have a simple delete link:

<?php echo $this->Html->link(__('remove', true), array('controller' =>
'carts', 'action' => 'delete', $item['Cart']['id']), null,
sprintf(__('Are you sure you want to remove %s?', true), $item['Cart']
['name'])); ?>

Two sample arrays:

Array
(
    [0] => Array
        (
            [_Token] => Array
                (
                    [key] => e031095578e465bb5c3b7c11318db719fc87a210
                    [fields] =>
8a8d3d32d202af510d5ba014c4904cd1540502a2%3An%3A3%3A%7Bv%3A0%3Bf%3A7%3A
%22Pneg.vq%22%3Bv%3A1%3Bf%3A9%3A%22Pneg.anzr%22%3Bv%3A2%3Bf%3A10%3A
%22Pneg.cevpr%22%3B%7D
                )

            [Cart] => Array
                (
                    [id] => 10
                    [name] => Credits
                    [price] => 15.00
                    [qty] => 10
                )

        )

    [1] => Array
        (
            [_Token] => Array
                (
                    [key] => e031095578e465bb5c3b7c11318db719fc87a210
                    [fields] =>
f77394c7e062f7b991d47ddba244bd20de4ffa87%3An%3A3%3A%7Bv%3A0%3Bf%3A7%3A
%22Pneg.vq%22%3Bv%3A1%3Bf%3A9%3A%22Pneg.anzr%22%3Bv%3A2%3Bf%3A10%3A
%22Pneg.cevpr%22%3B%7D
                )

            [Cart] => Array
                (
                    [id] => 20
                    [name] => Audio
                    [price] => 25.00
                    [qty] => 20
                )

        )
)

Here is my delete function in the controller.


function delete($id = null) {
                if ($this->Session->delete('sCart.0.Cart.id')) {
                        $this->Session->setFlash(sprintf(__('%s removed', 
true), 'Item'));
                        $this->redirect(array('controller' => 'credits',
'action'=>'addcredits', 8));
                }
                $this->Session->setFlash(sprintf(__('%s was not removed', true),
'Item'));
                $this->redirect(array('controller' => 'credits',
'action'=>'addcredits', 8));
        }

It is deleting the id field from the array but not the array itself.
I am also worried that it may not delete the token of that array
either.  Is there a way to add some kind of id to each main array so
the delete takes care of the token and Cart arrays inside the main
array?

Thank you for your help.

Brad

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to