Archives for September, 2011
// Symfony 2 public function updateAction($id) { $em = $this->getDoctrine()->getEntityManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException('No product found for id '.$id); } $product->setName('New product name!'); $em->flush(); return $this->redirect($this->generateUrl('homepage')); } # Django def updateAction(request, id): product = Product.objects.get(pk=id) # Product.DoesNotExist exception raised if not found product.name = u"New product name!" product.save() return HttpResponseRedirect(reverse('homepage'))
Recent Comments