当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setLocale方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setLocale方法的具体用法?PHP Request::setLocale怎么用?PHP Request::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Request的用法示例。


在下文中一共展示了Request::setLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onKernelException

 /**
  * Event handler that renders custom pages in case of a NotFoundHttpException (404)
  * or a AccessDeniedHttpException (403).
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ('dev' == $this->kernel->getEnvironment()) {
         return;
     }
     $exception = $event->getException();
     $this->request->setLocale($this->defaultLocale);
     $this->request->setDefaultLocale($this->defaultLocale);
     if ($exception instanceof NotFoundHttpException) {
         $section = $this->getExceptionSection(404, '404 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $this->request->setLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->request->setDefaultLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->entityManager->getRepository('UnifikSystemBundle:Section')->setLocale($this->request->attributes->get('_locale'));
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:404.html.twig', array('section' => $section));
         $response->setStatusCode(404);
         $event->setResponse($response);
     } elseif ($exception instanceof AccessDeniedHttpException) {
         $section = $this->getExceptionSection(403, '403 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:403.html.twig', array('section' => $section));
         $response->setStatusCode(403);
         $event->setResponse($response);
     }
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:35,代码来源:ExceptionListener.php

示例2: language

 public function language($language = null)
 {
     $session = $this->container->get('session');
     if ($language == null) {
         if (!$session->get('_locale')) {
             $session->set('_locale', 'en');
         }
         $language = $session->get('_locale');
     }
     if ($language) {
         $this->request->setLocale($language);
     }
     return '';
 }
开发者ID:juanber84,项目名称:simplei18nbundle,代码行数:14,代码来源:Simplei18nExtension.php

示例3: indexAction

 /**
  * @Route("/{slugs}", name="orbitale_cms_page", requirements={"slugs": "([a-zA-Z0-9_-]+\/?)*"}, defaults={"slugs": ""})
  *
  * @param Request     $request
  * @param string      $slugs
  * @param string|null $_locale
  *
  * @return Response
  */
 public function indexAction(Request $request, $slugs = '', $_locale = null)
 {
     if (preg_match('~/$~', $slugs)) {
         return $this->redirect($this->generateUrl('orbitale_cms_page', array('slugs' => rtrim($slugs, '/'))));
     }
     $this->request = $request;
     $this->request->setLocale($_locale ?: $this->request->getLocale());
     $slugsArray = preg_split('~/~', $slugs, -1, PREG_SPLIT_NO_EMPTY);
     $pages = $this->getPages($slugsArray);
     $currentPage = $this->getCurrentPage($pages, $slugsArray);
     if ($currentPage->isHomepage() && strlen($slugs)) {
         return $this->redirect($this->generateUrl('orbitale_cms_page', array('slugs' => '', '_locale' => $this->request->getLocale())));
     }
     return $currentPage instanceof Response ? $currentPage : $this->render('OrbitaleCmsBundle:Front:index.html.twig', array('pages' => $pages, 'page' => $currentPage));
 }
开发者ID:sfarkas1988,项目名称:CmsBundle,代码行数:24,代码来源:PageController.php

示例4: indexAction

 /**
  * Index of the app
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request)
 {
     $locale = $request->get('_locale');
     $request->setLocale($locale);
     $request->getSession()->set('_locale', $locale);
     $session = $request->getSession();
     $securityContext = $this->container->get('security.context');
     if ($securityContext->isGranted('ROLE_ADMIN')) {
         return $this->redirectToRoute('admin_homepage');
     } elseif ($securityContext->isGranted('ROLE_USER')) {
         return $this->redirectToRoute('user_homepage');
     } else {
         $authErrorKey = Security::AUTHENTICATION_ERROR;
         $lastUsernameKey = Security::LAST_USERNAME;
         // get the error if any (works with forward and redirect -- see below)
         if ($request->attributes->has($authErrorKey)) {
             $error = $request->attributes->get($authErrorKey);
         } elseif (null !== $session && $session->has($authErrorKey)) {
             $error = $session->get($authErrorKey);
             $session->remove($authErrorKey);
         } else {
             $error = null;
         }
         if (!$error instanceof AuthenticationException) {
             $error = null;
             // The value does not come from the security component.
         }
         // last username entered by the user
         $lastUsername = null === $session ? '' : $session->get($lastUsernameKey);
         $csrfToken = $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue();
         return $this->render('BaseBundle:Default:index.html.twig', array('last_username' => $lastUsername, 'error' => $error, 'csrf_token' => $csrfToken));
     }
 }
开发者ID:smarquina,项目名称:misBeans,代码行数:39,代码来源:DefaultController.php

示例5: process

 /**
  * {@inheritdoc}
  */
 public function process(Request $request, RequestAttributes $requestAttributes)
 {
     $portalInformation = $requestAttributes->getAttribute('portalInformation');
     if (!$portalInformation instanceof PortalInformation) {
         return new RequestAttributes();
     }
     $attributes = ['requestUri' => $request->getUri()];
     if (null !== ($localization = $portalInformation->getLocalization())) {
         $request->setLocale($localization->getLocalization());
     }
     $attributes['portalInformation'] = $portalInformation;
     $attributes['getParameter'] = $request->query->all();
     $attributes['postParameter'] = $request->request->all();
     $attributes['matchType'] = $portalInformation->getType();
     $attributes['redirect'] = $portalInformation->getRedirect();
     $attributes['analyticsKey'] = $portalInformation->getAnalyticsKey();
     $attributes['portalUrl'] = $portalInformation->getUrl();
     $attributes['webspace'] = $portalInformation->getWebspace();
     $attributes['portal'] = $portalInformation->getPortal();
     if ($portalInformation->getType() === RequestAnalyzerInterface::MATCH_TYPE_REDIRECT) {
         return new RequestAttributes($attributes);
     }
     $attributes['localization'] = $portalInformation->getLocalization();
     $attributes['segment'] = $portalInformation->getSegment();
     list($resourceLocator, $format) = $this->getResourceLocatorFromRequest($portalInformation, $request);
     $attributes['urlExpression'] = $portalInformation->getUrlExpression();
     $attributes['resourceLocator'] = $resourceLocator;
     $attributes['format'] = $format;
     $attributes['resourceLocatorPrefix'] = substr($portalInformation->getUrl(), strlen($request->getHttpHost()));
     if (null !== $format) {
         $request->setRequestFormat($format);
     }
     return new RequestAttributes($attributes);
 }
开发者ID:sulu,项目名称:sulu,代码行数:37,代码来源:PortalInformationRequestProcessor.php

示例6: changeLocaleAction

 public function changeLocaleAction($code, Request $request)
 {
     $request->setLocale($code);
     $this->get('session')->set('_locale', $code);
     $referer = $request->headers->get('referer');
     return $this->redirect(empty($referer) ? "/" : $referer);
 }
开发者ID:beyzakokcan,项目名称:ojs,代码行数:7,代码来源:CommonController.php

示例7: profileAction

 /**
  * Users profile
  *
  * @param Request $request
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function profileAction(Request $request)
 {
     //set language
     $locale = $request->get('_locale');
     $request->setLocale($locale);
     $request->getSession()->set('_locale', $locale);
     //Security control. Check user roles.
     $response = $this->checkUserRole($request);
     if ($response instanceof RedirectResponse) {
         return $response;
     }
     $user = $this->getUser();
     $user_id = $user->getId();
     $gravatar = $this->getGravatar($user->getEmail());
     $em = $this->getDoctrine()->getManager();
     $form = $this->createForm(new UpdateUserType($user));
     $form->handleRequest($request);
     if ($request->isMethod('POST') && $form->isValid()) {
         $data = $form->getData();
         $user->setFullName($data['fullName']);
         $user->setEmail($data['email']);
         $em->flush();
         $this->get('session')->getFlashBag()->add('correct', '');
     }
     //buscar log de usuario
     $logLogic = new Loglogic();
     $logger = $logLogic->getLog($user_id, $em, $this->get('translator'));
     //actualizar password
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->get('fos_user.change_password.form.factory');
     $formPassword = $formFactory->createForm();
     $formPassword->setData($user);
     return $this->render('BaseBundle:User:profile.html.twig', array('userData' => $user, 'form' => $form->createView(), 'logger' => $logger, 'gravatar' => $gravatar, 'formPassword' => $formPassword->createView()));
 }
开发者ID:smarquina,项目名称:misBeans,代码行数:40,代码来源:UserController.php

示例8: testBackendRequest

 /**
  * Tests initializing the framework with a back end request.
  *
  * @runInSeparateProcess
  */
 public function testBackendRequest()
 {
     $request = new Request();
     $request->attributes->set('_route', 'dummy');
     $request->attributes->set('_scope', ContaoCoreBundle::SCOPE_BACKEND);
     $request->attributes->set('_contao_referer_id', 'foobar');
     $request->setLocale('de');
     $container = $this->mockContainerWithContaoScopes();
     $container->get('request_stack')->push($request);
     $framework = $this->mockContaoFramework($container->get('request_stack'), $this->mockRouter('/contao/install'));
     $framework->setContainer($container);
     $framework->initialize();
     $this->assertTrue(defined('TL_MODE'));
     $this->assertTrue(defined('TL_START'));
     $this->assertTrue(defined('TL_ROOT'));
     $this->assertTrue(defined('TL_REFERER_ID'));
     $this->assertTrue(defined('TL_SCRIPT'));
     $this->assertTrue(defined('BE_USER_LOGGED_IN'));
     $this->assertTrue(defined('FE_USER_LOGGED_IN'));
     $this->assertTrue(defined('TL_PATH'));
     $this->assertEquals('BE', TL_MODE);
     $this->assertEquals($this->getRootDir(), TL_ROOT);
     $this->assertEquals('foobar', TL_REFERER_ID);
     $this->assertEquals('contao/install', TL_SCRIPT);
     $this->assertEquals('', TL_PATH);
     $this->assertEquals('de', $GLOBALS['TL_LANGUAGE']);
 }
开发者ID:bytehead,项目名称:core-bundle,代码行数:32,代码来源:ContaoFrameworkTest.php

示例9: postAction

 /**
  * @Route("/recommendation/post")
  * @Route("/{lang}/recommendation/post")
  * @Method("POST")
  */
 public function postAction(Request $request, $lang = 'ar')
 {
     $translator = $this->container->get('translator');
     $preferencesService = $this->container->get('system_preferences_service');
     $to = $preferencesService->SendRecommendationEmail;
     $defaultFrom = $preferencesService->EmailFromAddress;
     $response = array();
     $parameters = $request->request->all();
     $request->setLocale($lang);
     $form = $this->container->get('form.factory')->create(new SendRecommendationType(), array(), array());
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $date = new \DateTime("now");
             $subject = $translator->trans('plugin.recommendation.email.subject', array('%name%' => $data['person_name']), 'messages');
             $body = '';
             foreach ($data as $name => $value) {
                 if ($name == 'person_name') {
                     $body .= '<b>' . $translator->trans('plugin.recommendation.form.label.person_group_label') . '</b><br>';
                 } elseif ($name == 'recommendee_name') {
                     $body .= '<br><b>' . $translator->trans('plugin.recommendation.form.label.recommendee_group_label') . '</b><br>';
                 }
                 $body .= $translator->trans('plugin.recommendation.form.label.' . $name) . ': ' . $value . '<br>';
             }
             $emailService = $this->container->get('email');
             $emailService->send($subject, $body, $to, $defaultFrom);
             $response['response'] = array('status' => true, 'message' => $translator->trans('plugin.recommendation.msg.success'));
         } else {
             $response['response'] = array('status' => false, 'message' => $translator->trans('plugin.recommendation.msg.invalid'));
         }
         return new JsonResponse($response);
     }
 }
开发者ID:riverans,项目名称:plugin-SendRecommendationBundle,代码行数:39,代码来源:SendRecommendationController.php

示例10: listAction

 public function listAction(Request $request, $filter)
 {
     $user = $this->getUser();
     $em = $this->getDoctrine()->getManager();
     if ($user != null) {
         $request->setLocale($user);
         $listEvent = null;
         $listEvent = $em->getRepository('MdyXlagendaBundle:Event')->listEvents(null);
         return $this->render('MdyXlagendaBundle:Event:list.html.twig', array('listEvent' => $listEvent, 'filter' => $filter));
     } else {
         // utilisateur anonymous
         if ($request->isXmlHttpRequest()) {
             // il s'agit d'un appel AJAX
             if ($request->getMethod() == "POST") {
                 $filter = array();
                 $filter['lieu'] = $request->request->get('lieu');
                 $filter['rubrique'] = $request->request->get('rubrique');
                 $filter['dateDebut'] = $request->request->get('dateDebut');
                 $filter['dateFin'] = $request->request->get('dateFin');
                 $listEvent = $em->getRepository('MdyXlagendaBundle:Event')->findFilter($filter);
                 return $this->render('MdyXlagendaBundle:Event:visitor.ajax.twig', array('listEvent' => $listEvent));
             } else {
             }
         } else {
             // il s'agit d'un appel "standard"
             $listEvent = $em->getRepository('MdyXlagendaBundle:Event')->myFindAll();
             $listLieu = $em->getRepository('MdyXlagendaBundle:Lieu')->findAll();
             $listRubrique = $em->getRepository('MdyXlagendaBundle:Rubrique')->findAll();
             return $this->render('MdyXlagendaBundle:Event:visitor.html.twig', array('listEvent' => $listEvent, 'listLieu' => $listLieu, 'listRubrique' => $listRubrique, 'filter' => null));
         }
     }
 }
开发者ID:rthreis,项目名称:GST,代码行数:32,代码来源:EventController.php

示例11: setLocale

 private function setLocale(Request $request, $locale)
 {
     $request->setLocale($locale);
     if (null !== $this->router) {
         $this->router->getContext()->setParameter('_locale', $request->getLocale());
     }
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:7,代码来源:LocaleListener.php

示例12: setUp

 public function setUp()
 {
     $request = new Request(['q-a' => 1, 'q-b' => 2], [], ['foo' => 'bar', 'fee' => 'bee', 'fii' => 'bii', 'int' => 9, '_route_params' => ['zee' => 'zar']]);
     $request->setLocale('en');
     $requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')->disableOriginalConstructor()->getMock();
     $requestStack->method('getCurrentRequest')->willReturn($request);
     $this->api = new BlockFilterApi($requestStack);
 }
开发者ID:Silwereth,项目名称:core,代码行数:8,代码来源:BlockFilterApiTest.php

示例13: setLocale

 /**
  * @param HttpRequest $request
  * @param string $locale
  */
 public function setLocale(HttpRequest $request, $locale)
 {
     setlocale(LC_ALL, $locale);
     $locale = substr($locale, 0, 2);
     $request->setLocale($locale);
     $this->translator->setLocale($locale);
     $this->translatable->setTranslatableLocale($locale);
 }
开发者ID:anime-db,项目名称:app-bundle,代码行数:12,代码来源:Request.php

示例14: changeLocalizationAction

 public function changeLocalizationAction(Request $request, $_locale)
 {
     try {
         $request->setLocale($_locale);
         return new JsonResponse(array('success' => true));
     } catch (\Exception $ex) {
         return new JsonResponse(array('success' => false, 'message' => $ex->getMessage()));
     }
 }
开发者ID:bamper,项目名称:symfonypizzaexampleapp,代码行数:9,代码来源:OrderController.php

示例15:

 function it_sets_request_if_local_request_is_null($localeSettings, Request $request, ParameterBag $parameterBag)
 {
     $parameterBag->get('_locale')->willReturn(false);
     $request->attributes = $parameterBag;
     $localeSettings->getLanguage()->willReturn('fr_FR');
     $localeSettings->getLocale()->willReturn('fr_FR');
     $request->setLocale('fr_FR')->shouldBeCalled();
     $this->setRequest($request);
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:9,代码来源:LocalSubscriberSpec.php


注:本文中的Symfony\Component\HttpFoundation\Request::setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。