示例#1
0
文件: Route.php 项目: fraym/core
 /**
  * @param $menuItemTranslation
  * @return bool
  * @throws \Exception
  */
 protected function setupPage($menuItemTranslation)
 {
     try {
         $this->currentMenuItemTranslation = $menuItemTranslation;
         $this->currentMenuItem = $menuItemTranslation->menuItem;
         $this->db->setTranslatableLocale($menuItemTranslation->locale->locale);
         $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
         if ($this->request->isXmlHttpRequest() || $this->user->isAdmin()) {
             $localeId = $this->request->gp('locale_id');
             if ($localeId && is_numeric($localeId)) {
                 $this->locale->setLocale($localeId);
             } else {
                 $this->locale->setLocale($menuItemTranslation->locale);
             }
         } else {
             $this->locale->setLocale($menuItemTranslation->locale);
         }
         $pageTitle = (string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle;
         $pageTitle = str_replace('[SITE_NAME]', $menuItemTranslation->menuItem->site->name, $pageTitle);
         $this->template->setPageTitle($pageTitle);
         $this->template->setPageDescription($menuItemTranslation->description);
         $this->template->setKeywords(explode(',', $menuItemTranslation->keywords));
         setlocale(LC_ALL, $this->locale->getLocale()->locale);
     } catch (Exception $e) {
         throw new \Exception('Error setup page: ' . $e->getMessage());
     }
     return true;
 }