本文整理匯總了PHP中Basket::setOwner方法的典型用法代碼示例。如果您正苦於以下問題:PHP Basket::setOwner方法的具體用法?PHP Basket::setOwner怎麽用?PHP Basket::setOwner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Basket
的用法示例。
在下文中一共展示了Basket::setOwner方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addBasketAction
/**
* Add Basket page controller.
*
* @param integer $id vinyl id
* @param Application $app Silex application
*/
public function addBasketAction($id, Application $app)
{
if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) {
$baskets = $app['dao.basket']->findAllByIdUser($app['user']->getId());
$categories = $app['dao.category']->findAll();
$vinyl = $app['dao.vinyl']->find($id);
foreach ($baskets as $basket) {
if ($vinyl->getId() == $basket->getVinyl()->getId()) {
$basket->setQuantity($basket->getQuantity() + 1);
$app['dao.basket']->save($basket);
$app['session']->getFlashBag()->add('success', "Le vinyl a bien été enregistré dans votre panier");
return $app['twig']->render('vinyl.html.twig', array('categories' => HomeController::getCategories($app), 'baskets' => $baskets, 'vinyl' => $vinyl));
}
}
$newBasket = new Basket();
$newBasket->setQuantity(1);
$newBasket->setVinyl($vinyl);
$newBasket->setOwner($app['user']);
//return connected user
$app['dao.basket']->save($newBasket);
$app['session']->getFlashBag()->add('success', "Le vinyl a bien été enregistré dans votre panier");
return $app['twig']->render('vinyl.html.twig', array('categories' => HomeController::getCategories($app), 'baskets' => $baskets, 'vinyl' => $vinyl));
}
}