本文整理匯總了PHP中Symfony\Component\HttpFoundation\Session\Session::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::count方法的具體用法?PHP Session::count怎麽用?PHP Session::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\Session\Session
的用法示例。
在下文中一共展示了Session::count方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: indexAction
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$session = new Session();
if ($session->isStarted() == true) {
$session->start();
}
$products = $this->getDoctrine()->getRepository('AppBundle:Product')->findAll();
$prodId = $request->request->get('prod', 'noone');
$inBasket[] = "Empty Basket, please select a product";
if ($prodId != 'noone') {
$product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($prodId);
$session->set($product->getId(), $product->getName());
$log = new Log();
$log->setProdName($product->getName());
$log->setDate(new \DateTime());
$em = $this->getDoctrine()->getManager();
$em->persist($log);
$em->flush();
echo "Dev : Log saved to database. Product name - " . $product->getName() . " Current time - " . $log->getDate()->format('H:i:s \\O\\n Y-m-d');
$inBasket = $session->all();
} else {
if ($session->count() != 0) {
$inBasket = $session->all();
echo "Please select a Product before submitting !!!";
}
}
return $this->render('default/index.html.twig', ['products' => $products, 'basketProds' => $inBasket]);
}