/** * Get the current category based on the URL * * @throws Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function getCategory() { $path = $this->request->segment(1); $this->category = Category::findPublicCategory($path); if (!$this->category) { throw new NotFoundHttpException('Category not found.'); } return $this->category; }