Symfony\Component\HttpFoundation\Request::getLocale PHP Method

getLocale() public method

Get the locale.
public getLocale ( ) : string
return string
    public function getLocale()
    {
        return null === $this->locale ? $this->defaultLocale : $this->locale;
    }

Usage Example

Example #1
0
 /**
  * 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])]);
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::getLocale