/**
  * Recognizes a need to convert the redirect to a JSON response.
  */
 public function redirect($url, $statusCode = 302)
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         $url = $this->getController()->genUrl($url, true);
         $params = array('success' => true, 'redirect' => $url);
         $response = $this->getResponse();
         $response->clearHttpHeaders();
         $response->setStatusCode(200);
         $response->setContent(json_encode($params));
         $response->send();
         throw new sfStopException();
     } else {
         parent::redirect($url, $statusCode);
     }
 }
 public function redirectWithInfo($message, $url = 'default/index')
 {
     $this->getUser()->setFlash('info', $message);
     parent::redirect($url);
 }
Пример #3
0
 public static function processAction(sfActions $action)
 {
     if ($action->getRequest()->hasParameter("removeFromFavorites")) {
         self::removeFromFavorites($action->getRequest()->getParameter("removeFromFavorites"));
         $action->redirect("my-favorites/index");
     } elseif ($action->getRequest()->hasParameter("addToFavorites")) {
         self::addToFavorites($action->getRequest()->getParameter("addToFavorites"));
         $action->redirect("my-favorites/index");
     }
 }