public function rate($id) { $this->respondTo('html', function () use($id) { try { $userSession = UserSession::getInstance(); if (!$userSession->isSignedIn()) { throw new ActionNotAuthorizedException(); } Rating::create($userSession->getUser(), Product::find($id), $this->getRequest()->getParams()); $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]); } catch (ResourceNotFoundException $e) { $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]); } catch (ValidationException $e) { $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]); } catch (DuplicateResourceException $e) { $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]); } catch (ActionNotAuthorizedException $e) { $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]); } }); }