public function view($slug = null)
    {
        //The category can be passed as query string, from a widget
        if ($this->request->getQuery('q')) {
            return $this->redirect([$this->request->getQuery('q')]);
        }

        $category = $this->PagesCategories->findActiveBySlug($slug)
            ->select(['id', 'title'])
            ->contain($this->PagesCategories->Pages->getAlias(), function (Query $q) {
                return $q->find('active')->select(['category_id', 'slug', 'title']);
            })
            ->cache(sprintf('category_%s', md5($slug)), $this->PagesCategories->getCacheName())
            ->firstOrFail();

        $this->set(compact('category'));
    }