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


PHP Request::getLocale方法代码示例

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


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

示例1: indexAction

 /**
  * New page.
  *
  * @Route("/index/{blogId}/{tab}", name="victoire_blog_index", defaults={"blogId" = null, "tab" = "articles"})
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function indexAction(Request $request, $blogId = null, $tab = 'articles')
 {
     /** @var BlogRepository $blogRepo */
     $blogRepo = $this->get('doctrine.orm.entity_manager')->getRepository('VictoireBlogBundle:Blog');
     $blogs = $blogRepo->joinTranslations($request->getLocale())->run();
     $blog = reset($blogs);
     if (is_numeric($blogId)) {
         $blog = $blogRepo->find($blogId);
     }
     $options['blog'] = $blog;
     $options['locale'] = $request->getLocale();
     $template = $this->getBaseTemplatePath() . ':index.html.twig';
     $chooseBlogForm = $this->createForm(ChooseBlogType::class, null, $options);
     $chooseBlogForm->handleRequest($request);
     if ($chooseBlogForm->isValid()) {
         $blog = $chooseBlogForm->getData()['blog'];
         $template = $this->getBaseTemplatePath() . ':_blogItem.html.twig';
         $blogRepo->clearInstance();
         $chooseBlogForm = $this->createForm(ChooseBlogType::class, null, ['blog' => $blog, 'locale' => $request->getLocale()]);
     }
     $businessProperties = [];
     if ($blog instanceof BusinessTemplate) {
         //we can use the business entity properties on the seo
         $businessEntity = $this->get('victoire_core.helper.business_entity_helper')->findById($blog->getBusinessEntityId());
         $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');
     }
     return new JsonResponse(['html' => $this->container->get('templating')->render($template, ['blog' => $blog, 'currentTab' => $tab, 'tabs' => ['articles', 'settings', 'category'], 'chooseBlogForm' => $chooseBlogForm->createView(), 'businessProperties' => $businessProperties])]);
 }
开发者ID:victoire,项目名称:victoire,代码行数:37,代码来源:BlogController.php

示例2: newAction

 /**
  * New page.
  *
  * @param bool $isHomepage
  *
  * @return []
  */
 protected function newAction(Request $request, $isHomepage = false)
 {
     /** @var EntityManager $entityManager */
     $entityManager = $this->get('doctrine.orm.entity_manager');
     $page = $this->getNewPage();
     if ($page instanceof Page) {
         $page->setHomepage($isHomepage ? $isHomepage : 0);
     }
     $form = $this->get('form.factory')->create($this->getNewPageType(), $page);
     $form->handleRequest($this->get('request'));
     if ($form->isValid()) {
         if ($page->getParent()) {
             $pageNb = count($page->getParent()->getChildren());
         } else {
             $pageNb = count($entityManager->getRepository('VictoirePageBundle:BasePage')->findByParent(null));
         }
         // + 1 because position start at 1, not 0
         $page->setPosition($pageNb + 1);
         $page->setAuthor($this->getUser());
         $entityManager->persist($page);
         $entityManager->flush();
         // If the $page is a BusinessEntity (eg. an Article), compute it's url
         if (null !== $this->get('victoire_core.helper.business_entity_helper')->findByEntityInstance($page)) {
             $page = $this->get('victoire_business_page.business_page_builder')->generateEntityPageFromTemplate($page->getTemplate(), $page, $entityManager);
         }
         $this->congrat($this->get('translator')->trans('victoire_page.create.success', [], 'victoire'));
         $viewReference = $this->get('victoire_view_reference.repository')->getOneReferenceByParameters(['viewId' => $page->getId(), 'locale' => $request->getLocale()]);
         return ['success' => true, 'url' => $this->generateUrl('victoire_core_page_show', ['_locale' => $request->getLocale(), 'url' => $viewReference->getUrl()])];
     } else {
         $formErrorHelper = $this->get('victoire_form.error_helper');
         return ['success' => !$form->isSubmitted(), 'message' => $formErrorHelper->getRecursiveReadableErrors($form), 'html' => $this->get('templating')->render($this->getBaseTemplatePath() . ':new.html.twig', ['form' => $form->createView()])];
     }
 }
开发者ID:victoire,项目名称:victoire,代码行数:40,代码来源:BasePageController.php

示例3: localeRedirectAction

 /**
  * This route decides wheater a request has a missing locale or it is a missing page
  *
  * @param Request $request
  *
  * @return Response
  */
 public function localeRedirectAction(Request $request)
 {
     $requestUri = $request->getRequestUri();
     $explodedUri = explode('/', $requestUri);
     $doubleSlash = substr($requestUri, 0, 2) === '//';
     if (!$doubleSlash) {
         // does not start with 2 slashes
         if (strlen($explodedUri[1]) !== 2) {
             // no locale supplied
             $matchingRoute = $this->get('router')->match("/" . $requestUri);
         } else {
             // 404
             throw $this->createNotFoundException();
         }
     } else {
         $requestUri = substr($requestUri, 2);
         // Removed first 2 slashes
         $locale = empty($request->getLocale()) ? $request->getDefaultLocale() : mb_substr($request->getLocale(), 0, 2);
         $requestUri = '/' . $locale . '/' . $requestUri;
         $matchingRoute = $this->get('router')->match($requestUri);
     }
     if ($matchingRoute['_controller'] === 'Ashura\\OptionalLocaleBundle\\Controller\\DefaultController::localeRedirectAction') {
         throw $this->createNotFoundException();
     }
     return $this->forward($matchingRoute['_controller']);
 }
开发者ID:CoalaJoe,项目名称:OptionalLocaleBundle,代码行数:33,代码来源:DefaultController.php

示例4: getCurrentLocale

 /**
  * {@inheritdoc}
  */
 public function getCurrentLocale()
 {
     if (null === $this->request) {
         return $this->getFallbackLocale();
     }
     return $this->request->getLocale();
 }
开发者ID:vikey89,项目名称:Sylius,代码行数:10,代码来源:RequestLocaleProvider.php

示例5: crud

 /**
  * @param Request $request
  * @param $mode
  * @param null $securekey
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 private function crud(Request $request, $mode, $securekey = null)
 {
     $locale = $request->getLocale();
     $defaultLocale = $this->container->getParameter("SSone.default_locale");
     $em = $this->getDoctrine()->getManager();
     $ls = $this->get('ssone.cms.Localiser');
     $altLinks = $ls->getAltAdminLangLinks($request->getUri());
     if ($mode == "new") {
         $menuItem = new MenuItem();
     } else {
         $menuItem = $this->getDoctrine()->getRepository('SSoneCMSBundle:MenuItem')->findBySecurekey($securekey);
     }
     $contentLibrary = $this->get('ssone.cms.content')->getAllForGroupedChoiceOptions();
     $fieldsRepository = $this->getDoctrine()->getRepository('SSoneCMSBundle:Field');
     $menuItems = $this->get('ssone.cms.navigation');
     $menuItems = $menuItems->buildFlatNavigationArray($menuItem->getId());
     $form = $this->createForm(new MenuItemTYPE($request->getLocale(), $mode, $contentLibrary, $menuItems, $fieldsRepository), $menuItem);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->handleParentChoice($menuItem, $em);
         $this->handleContentChoice($menuItem, $em);
         $this->get('ssone.cms.recordauditor')->auditRecord($menuItem);
         switch ($mode) {
             case "new":
                 $em->persist($menuItem);
                 break;
             case "delete":
                 $em->remove($menuItem);
                 break;
         }
         $em->flush();
         return $this->redirect($this->generateUrl('ssone_cms_admin_menuItems_list'));
     }
     return $this->render('SSoneCMSBundle:MenuItem:crud.html.twig', array('form' => $form->createView(), 'menuItemTitle' => $menuItem->getName($defaultLocale), 'mode' => $mode, 'locale' => $locale, "altLinks" => $altLinks));
 }
开发者ID:ssone,项目名称:cms-bundle,代码行数:41,代码来源:MenuItemsController.php

示例6: indexAction

 /**
  * indexAction action.
  */
 public function indexAction(Request $request, $_format)
 {
     $session = $request->getSession();
     if ($request->hasPreviousSession() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
         // keep current flashes for one more request if using AutoExpireFlashBag
         $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
     }
     $cache = new ConfigCache($this->exposedRoutesExtractor->getCachePath($request->getLocale()), $this->debug);
     if (!$cache->isFresh()) {
         $exposedRoutes = $this->exposedRoutesExtractor->getRoutes();
         $serializedRoutes = $this->serializer->serialize($exposedRoutes, 'json');
         $cache->write($serializedRoutes, $this->exposedRoutesExtractor->getResources());
     } else {
         $serializedRoutes = file_get_contents((string) $cache);
         $exposedRoutes = $this->serializer->deserialize($serializedRoutes, 'Symfony\\Component\\Routing\\RouteCollection', 'json');
     }
     $routesResponse = new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $exposedRoutes, $this->exposedRoutesExtractor->getPrefix($request->getLocale()), $this->exposedRoutesExtractor->getHost(), $this->exposedRoutesExtractor->getScheme(), $request->getLocale());
     $content = $this->serializer->serialize($routesResponse, 'json');
     if (null !== ($callback = $request->query->get('callback'))) {
         $validator = new \JsonpCallbackValidator();
         if (!$validator->validate($callback)) {
             throw new HttpException(400, 'Invalid JSONP callback value');
         }
         $content = $callback . '(' . $content . ');';
     }
     $response = new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
     $this->cacheControlConfig->apply($response);
     return $response;
 }
开发者ID:kuczek,项目名称:FOSJsRoutingBundle,代码行数:32,代码来源:Controller.php

示例7: getFormOptions

 /**
  * @param Request $request
  * @param $type
  * @param $options
  *
  * @return array
  */
 protected function getFormOptions(Request $request, $type, $options)
 {
     $defaultOptions = ['locale' => $request->getLocale(), 'locales' => $this->getWebSpaceLocales(), 'type' => $type, 'contact_type' => $this->getConfig(Configuration::FORM_TYPES, Configuration::FORM_TYPE_CONTACT), 'contact_address_type' => $this->getConfig(Configuration::FORM_TYPES, Configuration::FORM_TYPE_CONTACT_ADDRESS), 'address_type' => $this->getConfig(Configuration::FORM_TYPES, Configuration::FORM_TYPE_ADDRESS), 'user_class' => $this->getUserClass(), 'contact_type_options' => ['label' => false, 'type' => $type, 'locale' => $request->getLocale()], 'contact_address_type_options' => ['label' => false, 'type' => $type, 'locale' => $request->getLocale()], 'address_type_options' => ['label' => false, 'type' => $type, 'locale' => $request->getLocale()]];
     if (in_array($type, [Configuration::TYPE_REGISTRATION, Configuration::TYPE_PROFILE])) {
         $defaultOptions['data_class'] = $this->getUserClass();
     }
     return array_merge($defaultOptions, $options);
 }
开发者ID:alexander-schranz,项目名称:sulu-website-user-bundle,代码行数:15,代码来源:AbstractController.php

示例8: buildForm

 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $search_choices = ['' => 'No'];
     foreach ($this->chain->getPlugins() as $plugin) {
         $search_choices[$plugin->getName()] = $plugin->getTitle();
     }
     $builder->add('locale', 'locale', ['label' => 'Language', 'data' => $this->request ? $this->request->getLocale() : ''])->add('default_search', 'choice', ['required' => false, 'choices' => $search_choices, 'label' => 'Default search plugin']);
 }
开发者ID:anime-db,项目名称:catalog-bundle,代码行数:12,代码来源:Settings.php

示例9: dispatch

 public function dispatch($options)
 {
     $locale = strtoupper($this->request->getLocale());
     $methodName = sprintf('%s%s', 'isValid', $locale);
     if (method_exists($this, $methodName)) {
         return call_user_func(array($this, $methodName), $options);
     }
     return true;
 }
开发者ID:ywoume,项目名称:sudmadatrek,代码行数:9,代码来源:BankValidator.php

示例10: indexAction

 /**
  * @Route("/mediateca/{sort}", defaults={"sort" = "date"}, requirements={"sort" = "alphabetically|date"}, name="pumukit_webtv_medialibrary_index")
  * @Template()
  */
 public function indexAction($sort, Request $request)
 {
     $repo = $this->get('doctrine_mongodb')->getRepository('PumukitSchemaBundle:Series');
     $sortField = "alphabetically" == $sort ? 'title.' . $request->getLocale() : "public_date";
     $criteria = $request->query->get('search', false) ? array('title.' . $request->getLocale() => new \MongoRegex(sprintf("/%s/i", $request->query->get('search')))) : array();
     $series = $repo->findBy($criteria, array($sortField => 1));
     $this->get('pumukit_web_tv.breadcrumbs')->addList("All", "pumukit_webtv_medialibrary_index");
     return array('series' => $series, 'sort' => $sort);
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:13,代码来源:MediaLibraryController.php

示例11: createFrontendLangMenu

 /**
  * Creates the login and change language navigation for the right side of the top frontend navigation
  *
  * @param Request $request
  * @param $languages
  * @param string $classes
  * @param bool $dropDownMenu
  * @return \Knp\Menu\ItemInterface
  */
 public function createFrontendLangMenu(Request $request, $languages, $classes = 'nav pull-right', $dropDownMenu = false)
 {
     $menu = $this->factory->createItem('root');
     $menu->setChildrenAttribute('class', $classes);
     if ($dropDownMenu) {
         $this->createDropdownLangMenu($menu, $languages, $request->getLocale());
     } else {
         $this->createInlineLangMenu($menu, $languages, $request->getLocale());
     }
     return $menu;
 }
开发者ID:lzdv,项目名称:init-cms-bundle,代码行数:20,代码来源:FrontendMenuBuilder.php

示例12: newsListAction

 public function newsListAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $pageRepository = $em->getRepository('KitpagesCmsBundle:Page');
     $page = $pageRepository->findOneBySlug($request->getLocale() . '-news');
     $paginator = new Paginator();
     $paginator->setCurrentPage($this->get('request')->query->get('news_page', 1));
     $paginator->setItemCountPerPage(3);
     $paginator->setUrlTemplate($this->generateUrl("news", array('news_page' => '_PAGE_', '_locale' => $request->getLocale())));
     return $this->render('AppSiteBundle:Default:news-list.html.twig', array('paginator' => $paginator, 'kitCmsPage' => $page, 'kitMeta' => array('title' => $this->get('translator')->trans('Drumming news !'), 'description' => $this->get('translator')->trans('Latest drumming news !'))));
 }
开发者ID:kitpages,项目名称:kitpages-cms-edition,代码行数:11,代码来源:DefaultController.php

示例13: parseRequest

 /**
  * (non-PHPdoc)
  * @see Spewia\Router.RouterInterface::parseRequest()
  * @throws Spewia\Router\Exception\RouteI18nIncorrectLanguageException
  */
 public function parseRequest(Request $request)
 {
     //check if any of the entries in the patterns is the same that the uri passed in the Request
     $identifier = $this->getIdentifierByUri($request->getPathInfo(), $request->getLocale());
     if ($identifier === NULL) {
         throw new RouteNotFoundException();
     }
     $params = $this->getParamsFromRequestUri($identifier, $request->getPathInfo(), $request->getLocale());
     $this->routing_configuration[$identifier]['params'] = $params;
     return $this->routing_configuration[$identifier];
 }
开发者ID:spewia,项目名称:spewia,代码行数:16,代码来源:RouterSpewiaI18n.php

示例14: onAuthenticationSuccess

 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
         $response = new RedirectResponse($this->router->generate('club_dashboard_admindashboard_index', array('_locale' => $request->getLocale())));
     } elseif ($this->security->isGranted('ROLE_ADMIN')) {
         $response = new RedirectResponse($this->router->generate('club_dashboard_admindashboard_index', array('_locale' => $request->getLocale())));
     } elseif ($this->security->isGranted('ROLE_USER')) {
         $response = new RedirectResponse($this->router->generate('club_dashboard_dashboard_index', array('_locale' => $request->getLocale())));
     }
     return $response;
 }
开发者ID:miteshchavada,项目名称:clubmaster,代码行数:11,代码来源:SuccessLoginHandler.php

示例15: generateLocaleAction

 /**
  * @Route("/locale.json")
  */
 public function generateLocaleAction(Request $request)
 {
     $translations = $this->getAllTranslations($request->getLocale());
     // cache the result when we're in production environment
     if ($this->container->get('kernel')->getEnvironment() === 'prod') {
         $webDir = $this->get('kernel')->getRootDir() . '/../web/';
         $fs = new Filesystem();
         $fs->dumpfile($webDir . $request->getLocale() . '/locale.json', json_encode($translations));
     }
     $response = new JsonResponse();
     $response->setData($translations);
     return $response;
 }
开发者ID:sumocoders,项目名称:framework-core-bundle,代码行数:16,代码来源:DefaultController.php


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