ランダムな試行回数の後にremoveAction
関数が機能する理由がわかりません。ときには、それが動作するまで、最初と他の(4または5回)を何度も何度もクリックしなければならないことがあります。ランダムな試行回数の後に関数ロジックが機能する
商品IDがユーザーのカートから削除されたため、正常に動作しています。
私はこのことができますかはわからないが、私は(float(0.0148420333862)
ある)機能のmicrotime()
に対して(30
です)max_execution_timeにチェック。
私が$quantity
と$cart
をダンプすると、常に正しい製品IDが表示されます。
removeAction function
:
/**
* Removes a 'product' from the cart
*
* @Route("/{id}/remove", name="product_remove")
* @METHOD("GET")
* @Template()
*/
public function removeAction(Request $request, $id) {
// $time = microtime(true);
$em = $this->getDoctrine()->getManager();
$product = $em->getRepository('ShopBundle:Product')->find($id);
$cart = $em->getRepository('ShopBundle:UserCart')->findOneBy(['user' => $this->getUser(), 'submitted' => false]);
$quantity = $em->getRepository('ShopBundle:Quantity')->findOneBy(['product' => $product->getId()]);
//get product id from the cart and then remove it
// product gets removed but only after a random # of click on the remove button...
//ini_get('max_execution_time');
//var_dump(ini_get('max_execution_time'));
// dump($quantity);
// dump($cart);
$em->remove($quantity);
$em->flush();
$this->addFlash('notice', 'The product: '.$product->getName().' was removed!');
//var_dump(microtime(true) - $time); die;
return $this->redirectToRoute('product_showCart');
}
これは奇妙なやり方です。私はそれがどのように働くのか分からないのですか?確かに、カートとその中の製品との関係はありますか?同じ商品が複数のカートにある場合はどうなりますか?そのコードはどのカートから取り除くべきかをどのように知っていますか?あなたの方法は私がそれを読むときにはあまり意味がありません。私はこれが標準的な方法でうまくいくと思います。 – Richard
これはおそらくこの笑いを行う奇妙な方法です。私は新しいですが、私は学んでいます。私はこれを有効にすることができましたが、これを修正しました: '$ quantity = $ em-> getRepository( 'ShopBundle:Quantity') - > findOneBy(['product' => $ product-> getId()])' :$ item = $ em-> getRepository( 'ShopBundle:Quantity') - > findOneBy(['product' => $ product-> getId()、 'userCart' => $ cart-> getId()]); ' – Ale
それは良く見えます:) – Richard