Example #1
0
 /**
  * Get the layout obj for a particular page under a route id
  *
  * @param int|string $page
  * @param int|null $route_id
  *
  * @return Record\Page
  */
 public function get($page, $route_id = null)
 {
     if (empty($route_id)) {
         if (Session::has('laymode/route')) {
             $route_id = Session::get('laymode/route');
         }
     }
     $this->page = $this->getPage($page, $route_id);
     if (empty($this->page) || !$this->page instanceof Page) {
         Log::error('The page ' . $page . ' does not exist for route id: ' . $route_id);
         App::abort('403', 'The page ' . $page . ' does not exist for route id: ' . $route_id);
     }
     if ($this->page->hasDesktopLayout()) {
         $md = new MobileDetect();
         if ($md->isMobile() && $page->hasMobileLayout()) {
             $this->page->set_mobile(1);
             $this->layout = $this->getLayout($this->page->get_mobile_layout_id(), $this->page->get_name(), true);
             $this->page->set_layout($this->layout);
         } else {
             $this->layout = $this->getLayout($this->page->get_desktop_layout_id(), $this->page->get_name(), false);
             $this->page->set_layout($this->layout);
         }
     }
     if ($this->layout instanceof Layout || $this->layout instanceof LayoutFromFile) {
         if (View::exists('templates.' . $this->layout->get_template())) {
             View::share('page', $this->page);
             return View::make('templates.' . $this->layout->get_template());
         } else {
             Log::error('The template ' . $this->layout->get_template() . ' does not exist');
             App::abort('403', 'The template ' . $this->layout->get_template() . ' does not exist');
         }
     } else {
         Log::error('No layout available for this page: ' . $page . ' and route: ' . $route_id);
         App::abort('403', 'No layout available for this page: ' . $page . ' and route: ' . $route_id);
     }
     return Redirect::to('/404');
 }