0

And then another message mostly the same saying

Declaration of Cart::save() should be compatible with Model::save

The basic problem is that the cart refuses to update whenever I try to add a product to it(its a simple ajax script). I wish I could talk more about this but I have no clue whats wrong. I have tried passing different parameters into the function but nothing works. Here are the relevant fucntions, sorry it being long.

CartsController:

    $carts = $this->Cart->read();
    $products = array();
    if (null!=$carts) {
        foreach ($carts as $productId => $count) {
            $product = $this->Product->read(null,$productId);
            $product['Product']['count'] = $count;
            $products[]=$product;
        }
    }
    $this->set(compact('products'));
}

    public function update() {
        if ($this->request->is('post')) {
            if (!empty($this->request->data)) {
                $cart = array();
                foreach ($this->request->data['Cart']['count'] as $index=>$count) {
                    if ($count>0) {
                        $productId = $this->request->data['Cart']['product_id'][$index];
                        $cart[$productId] = $count;
                    }
                }
                $this->Cart->save($cart);
            }
        }
        $this->redirect(array('action'=>'view'));
}

Cart Model:

public function save($data) {
    return CakeSession::write('cart',$data);
}

/*
 * read cart data from session
 */
public function read($data) {
    return CakeSession::read('cart', $data);
}

Thanks for any help.

Strobe_
  • 495
  • 1
  • 13
  • 34
  • Don't overwrite save()/read() and other model methods unless you know what you are doing. – mark Apr 10 '14 at 22:43

1 Answers1

1

This kind of question has now been asked a felt million times on Stackoverflow. Here is the basic workflow of how to deal with compiler errors and notices that will for sure help you to solve them all on your own:

  1. Read error message
  2. Think about it for a moment
  3. Google for the error message

The error tells you that your method signature must match the inherited parents signature. The arguments must match.

As mark already has mentioned in a comment, overloading the core class methods should only be done if you're pretty sure that you know what you're doing. if not this is very likely ending up in a pile of fail.

You can disable the strict errors but this is really not recommended, they exist for a reason. See How to eliminate php5 Strict standards errors?

Looks like you're doing a cart, well, here is my gift for the CakePHP ecommerce developers: https://github.com/burzum/cakephp-cart-plugin

Community
  • 1
  • 1
floriank
  • 25,546
  • 9
  • 42
  • 66