本文整理匯總了PHP中Symfony\Component\HttpFoundation\Session\Session::getFlashBag方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::getFlashBag方法的具體用法?PHP Session::getFlashBag怎麽用?PHP Session::getFlashBag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\Session\Session
的用法示例。
在下文中一共展示了Session::getFlashBag方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onKernelResponse
/**
* Moves flash messages from the session to a cookie inside a Response Kernel listener.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
return;
}
// Flash messages are stored in the session. If there is none, there
// can't be any flash messages in it. $session->getFlashBag() would
// create a session, we need to avoid that.
if (!$this->session->isStarted()) {
return;
}
$flashBag = $this->session->getFlashBag();
$flashes = $flashBag->all();
if (empty($flashes)) {
return;
}
$response = $event->getResponse();
$cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
if (isset($cookies[$this->options['host']][$this->options['path']][$this->options['name']])) {
$rawCookie = $cookies[$this->options['host']][$this->options['path']][$this->options['name']]->getValue();
$flashes = array_merge($flashes, json_decode($rawCookie));
}
$cookie = new Cookie($this->options['name'], json_encode($flashes), 0, $this->options['path'], $this->options['host'], $this->options['secure'], false);
$response->headers->setCookie($cookie);
}
示例2: createAction
public function createAction($article_id, Request $request)
{
$repository = $this->getDoctrine()->getRepository('BlogArticlesBundle:Article');
$query = $repository->createQueryBuilder('a')->where('a.isActive = 1')->where('a.id = :id')->setParameter('id', $article_id)->setMaxResults(1)->getQuery();
$article = $query->getOneOrNullResult();
if (!$article) {
throw $this->createNotFoundException('The article does not exist');
}
$comment = new Comment();
$form = $this->getForm($article_id, $comment);
$form->handleRequest($request);
$session = new Session();
if ($request->isMethod('POST')) {
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$comment->setArticle($article);
$comment->setIsActive(1);
$comment->setCreatedAt(new \DateTime('now'));
$em->persist($comment);
$em->flush();
$session->getFlashBag()->add('sucess', 'Save Done');
} else {
// $errors = array();
// foreach ($form->getErrors(true , true) as $key => $error) {
// $errors[] = $error->getMessage();
// }
$session->getFlashBag()->add('error', 'All fileds required');
}
}
return $this->redirect($this->generateUrl('BlogArticles_view', ['slug' => $article->getSlug()]) . '#comments');
}
示例3: addFlashMessage
/**
* @param string $type
* @param string $message
* @throws MissingDependencyException
*/
public function addFlashMessage($type, $message)
{
if (null === $this->session) {
throw new MissingDependencyException('No session present.');
}
$this->session->getFlashBag()->add($type, $message);
}
示例4: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$request = $event->getRequest();
$fc_form = $this->form_service->guessFcForm($request);
if (!$fc_form instanceof FcForm) {
return;
}
if ($fc_form->getAction()) {
return;
}
/** @var FormInterface $form */
$form = $this->form_service->create($fc_form);
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$this->form_service->clear($fc_form, array('template' => $data['_template'], 'data' => $this->form_service->initData($data)));
if ($fc_form->getIsAjax()) {
return;
}
if ($fc_form->getMessage()) {
$message = $fc_form->getMessage();
} else {
$message = $this->translator->trans('fc.message.form.is_valid', array(), 'FenrizbesFormConstructorBundle');
}
// TODO: Связывать сообщение с конкретной формой и подчищать старые
$this->session->getFlashBag()->add('fc_form.success', $message);
$response = new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')));
$event->setResponse($response);
}
}
示例5: alertifyFilter
/**
* Alertify filter
* @param TwigEnvironment $environment
* @param Session $session
*
* @return string
*/
public function alertifyFilter($environment, Session $session)
{
$flashes = $session->getFlashBag()->all();
$renders = array();
foreach ($flashes as $type => $flash) {
if ($type == "callback") {
foreach ($flash as $key => $currentFlash) {
$currentFlash['body'] .= $environment->render('AvAlertifyBundle:Modal:callback.html.twig', $currentFlash);
$session->getFlashBag()->add($currentFlash['engine'], $currentFlash);
$renders[$type . $key] = $this->alertifyFilter($session);
}
} else {
foreach ($flash as $key => $content) {
if (is_array($content)) {
$context = isset($content['context']) ? $content['context'] : null;
$defaultParameters = self::getDefaultParametersFromContext($context);
$parameters = array_merge($defaultParameters, $content);
} else {
$defaultParameters = self::getDefaultParametersFromContext(null);
$parameters = array_merge($defaultParameters, array('body' => $content));
}
$parameters['type'] = $type;
$renders[$type . $key] = $environment->render('AvAlertifyBundle:Modal:' . $parameters['engine'] . '.html.twig', $parameters);
}
}
}
return implode(' ', $renders);
}
示例6: notify
public function notify(RequestVerifiedEvent $event)
{
$payment = $event->getPayment();
$status = $event->getStatus()->getValue();
switch ($status) {
case GetHumanStatus::STATUS_AUTHORIZED:
case GetHumanStatus::STATUS_CAPTURED:
case GetHumanStatus::STATUS_REFUNDED:
$this->repository->clearCart();
$type = 'success';
break;
case GetHumanStatus::STATUS_CANCELED:
case GetHumanStatus::STATUS_EXPIRED:
case GetHumanStatus::STATUS_FAILED:
$type = 'danger';
break;
case GetHumanStatus::STATUS_PENDING:
case GetHumanStatus::STATUS_SUSPENDED:
$this->repository->clearCart();
$type = 'warning';
break;
case GetHumanStatus::STATUS_NEW:
case GetHumanStatus::STATUS_UNKNOWN:
$this->repository->clearCart();
$type = 'info';
break;
default:
throw new \RuntimeException('Unknown status ' . $status);
}
$formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::CURRENCY);
$this->session->getFlashBag()->add($type, $this->translator->trans('flash.payment.' . $type, ['%status%' => $this->translator->trans('meta.status.' . $status), '%amount%' => $formatter->formatCurrency($payment->getTotalAmount() / 100, $payment->getCurrencyCode())]));
}
示例7: testAddFlashMessage
public function testAddFlashMessage()
{
$type = 'test_type';
$message = 'Test Message';
$this->assertEmpty($this->session->getFlashBag()->all());
$this->manager->addFlashMessage($type, $message);
$this->assertEquals([$type => [$message]], $this->session->getFlashBag()->all());
}
示例8: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof NoAdministrationException) {
$this->session->getFlashBag()->add('danger', $this->translator->trans('administration.none_found', array()));
$response = new RedirectResponse($this->router->generate('manage_administrations'));
$event->setResponse($response, 307);
}
}
示例9: getUser
/**
* Get the currently logged in user
*
* @throws AccessDeniedHttpException When no currently logged in user exists in the session
*
* @return User
*/
public function getUser()
{
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof User) {
$this->session->getFlashBag()->add(self::ERROR_TYPE, self::ERROR_MESSAGE);
throw new AccessDeniedHttpException(self::ERROR_MESSAGE);
}
return $this->entityManager->merge($user);
}
示例10: onKernelResponse
/**
* @param FilterResponseEvent $event
**/
public function onKernelResponse(FilterResponseEvent $event)
{
if ('html' === $this->responseFormat) {
return;
}
$flashBag = $this->session->getFlashBag();
$message = $flashBag->get(Constant::MESSAGE_SAVE, $flashBag->get(Constant::MESSAGE_UPDATE, $flashBag->get(Constant::MESSAGE_DELETE)));
$event->getResponse()->setContent($this->serializer->serialize($message, array(), $this->responseFormat));
}
示例11: renderMessages
/**
* @param null|string $type Message type. If null returns all types messages,
* otherwise returns messages only with given types.
* @return string
*/
public function renderMessages($type = null)
{
if ($type === null) {
$messages = $this->session->getFlashBag()->all();
} else {
$messages[$type] = $this->session->getFlashBag()->get($type);
}
return $this->environment->render('ArturDoruchFlashMessageBundle::messages.html.twig', array('messages' => $messages));
}
示例12: indexAction
/**
* @Route("/", name="index")
* @Template
*
* @return Response
*/
public function indexAction(Request $request)
{
$form = $this->formFactory->create('add_event');
$form->handleRequest($request);
if ($form->isValid()) {
$this->session->getFlashBag()->add('success', 'Your event have been successfully added !');
$form = $this->formFactory->create('add_event');
}
return ['form' => $form->createView()];
}
示例13: preDelete
/**
* @param GenericEvent $event
*/
public function preDelete(GenericEvent $event)
{
if (!($subject = $event->getSubject()) instanceof CustomerInterface) {
throw new UnexpectedTypeException($subject, 'Sylius\\Component\\Core\\Model\\CustomerInterface');
}
if ('sylius@example.com' === $subject->getEmail()) {
$this->session->getFlashBag()->add("error", "sylius_demo.account.prevent_delete");
$event->stopPropagation();
}
}
示例14: __construct
public function __construct(Container $container)
{
$this->container = $container;
$this->session = $this->container->get('session');
$this->flash = $this->session->getFlashBag();
$this->view = $this->container->get('view');
$this->request = $this->container->get('current_request');
$this->router = $this->container->get('router');
$this->config = $this->container->get('config');
$this->initialize();
}
示例15: getAlerts
/**
* @inheritdoc
*/
public function getAlerts()
{
$alerts = array();
foreach (self::getAlertTypes() as $type) {
$messages = $this->session->getFlashBag()->get($type);
if (!empty($messages)) {
$alerts = array_merge($alerts, $this->createAlertsForType($type, $messages));
}
}
return $alerts;
}