Example #1
0
 /**
  * Redirect to another page. Can redirect in a few different ways. URL redirects will
  * automagically determine the relative path based on which server we're on.
  * On development it will prepend /~{username}/{caseCode}/ to the URL.
  *
  * Redirect directly to an URL.
  * <code>
  *  <?php
  *  ...
  *  $this->redirectTo('/path/to/url');
  *  ...
  *  ?>
  * </code>
  *
  * Redirect to a specific controller/action
  * <code>
  *  <?php
  *  ...
  *  $this->redirectTo(
  *      array('controller' => 'browse',
  *            'action'     => 'briefcases',
  *            'id'         => '3',
  *            'sort'       => 'name'));
  *  ...
  *  ?>
  * </code>
  *
  * Redirect to a action within this same controller
  * <code>
  *  <?php
  *  ...
  *  $this->redirectTo(
  *      array('action'     => 'briefcases',
  *            'id'         => '3',
  *            'sort'       => 'name'));
  *  ...
  *  ?>
  * </code>
  *
  * @param  string|array  $first   named route, string, or options array
  * @param  array         $second  options array (if not in $first)   
  * @return null
  * @throws Mad_Controller_Exception
  */
 protected function redirectTo($first = array(), $second = array())
 {
     // should not render/redirect more than once
     if ($this->_performed()) {
         $msg = "Double render error: <b>{$this->_action}</b>";
         throw new Mad_Controller_Exception($msg);
     }
     if ($first === 'back') {
         // redirect to previous request
         $url = $this->_request->getServer('HTTP_REFERER');
         if (empty($url)) {
             $msg = "No HTTP_REFERER was set in the request to this action, " . "so redirectTo('back') could not be called successfully. " . " If this is a test, make sure to specify [\"HTTP_REFERER\"]";
             throw new Mad_Controller_Exception($msg);
         }
     } else {
         // generate the url
         $url = $this->getUrlWriter()->urlFor($first, $second);
     }
     $this->_response->setBody('Redirecting...');
     $this->_response->redirect($url);
     $this->_performedRedirect = true;
 }
Example #2
0
 /**
  * Dispatch the request to the correct controller
  *
  * @param  null|Mad_Controller_Request_Http  $request
  * @param  null|Mad_Controller_Response_Http $response
  * @return void
  */
 public function dispatch($request = null, $response = null)
 {
     $t = new Horde_Support_Timer();
     $t->push();
     if ($response === null) {
         $response = new Mad_Controller_Response_Http();
     }
     if ($request === null) {
         $request = new Mad_Controller_Request_Http();
     }
     // request could not be parsed
     if ($request->isMalformed()) {
         $body = "Your request could not be understood by the server, " . "probably due to malformed syntax.\n\n";
         $exc = $request->getException();
         if ($exc && MAD_ENV != 'production') {
             $body .= $exc->getMessage();
         }
         $response->setStatus(400);
         $response->setBody($body);
         // dispatch request to controller
     } else {
         $controller = $this->recognize($request);
         $response = $controller->process($request, $response);
     }
     $time = $t->pop();
     $this->_logRequest($request, $time);
     $response->send();
 }