0

I've created an entity that I can't update using doctrine-generated form. Here's an action:

    public function executeEdit(sfWebRequest $request)
{

    $this->forward404Unless($id = $request->getParameter('id'), "Required parameter 'id' must be present in request");

    $this->forward404Unless($cart = Doctrine::getTable('ShoppingCart')->find($id), sprintf("No object could be retrieved by %s", $id));
    $this->id = $id;

    $this->form = new ShoppingCartForm($cart);

    if($request->isMethod(sfRequest::POST)) {
        $this->form->bind($request->getParameter('shopping_cart'));
        if ($this->form->isValid())
        {
            $cart = $this->form->save();

            $this->redirect(link_to('cart/show?id='.$cart->getId()));
        }
    }
}

Form's isNew() method returns false, but the sf_method is set to PUT. When I use sfRequest::PUT doctrine tries to add new entity with that id. It seems like it shouldn't behave like that so what I am doing wrong?

danio1024
  • 76
  • 4
  • Have you checked that $cart is not null after retrieving from the database? – Flosculus Jul 29 '13 at 09:20
  • Sure, it's always ShoppingCart object. – danio1024 Jul 29 '13 at 09:23
  • You could try setting the method to POST when it is PUT, failing that you can always override the form. Look into the behavior of `sfForm` when dealing with PUT requests. It seems strange that since you already provided the original object it would try to reinsert it. – Flosculus Jul 29 '13 at 09:34
  • When you say it creates a new entity, it sounds like the form binding overrides your cart id by a null value. Maybe you forgot to render the object id widget which is often hidden. – sinhix Aug 13 '13 at 14:20

0 Answers0