/** * Views page. * * It first checks if there's a static page, using all the passed * arguments. * Otherwise, it checks for the page in the database, using that slug. * * Static pages must be located in `APP/View/StaticPages/`. * @param string $slug Page slug * @return \Cake\Network\Response|void * @uses MeCms\Utility\StaticPage::get() * @uses MeCms\Utility\StaticPage::title() */ public function view($slug = null) { //Checks if there exists a static page $static = StaticPage::get($slug); if ($static) { $page = (object) am(['title' => StaticPage::title($slug)], compact('slug')); $this->set(compact('page')); return $this->render($static); } $page = $this->Pages->find('active')->select(['id', 'title', 'subtitle', 'slug', 'text', 'active', 'created', 'modified'])->contain(['Categories' => function ($q) { return $q->select(['title', 'slug']); }])->where([sprintf('%s.slug', $this->Pages->alias()) => $slug])->cache(sprintf('view_%s', md5($slug)), $this->Pages->cache)->firstOrFail(); $this->set(compact('page')); }