Example #1
0
 /**
  * 
  * Returns an escaped href or src attribute value for an action URI.
  * 
  * @param Solar_Uri_Action|string $spec The href or src specification.
  * 
  * @return string
  * 
  */
 public function actionHref($spec)
 {
     if ($spec instanceof Solar_Uri_Action) {
         // already an action uri object
         $href = $spec->get();
     } else {
         // build-and-fetch the string as an action spec
         $href = $this->_uri->quick($spec);
     }
     return $this->_view->escape($href);
 }
 /**
  * 
  * Issues an immediate "Location" redirect.  Use instead of display()
  * to perform a redirect.  You should die() or exit() after calling this.
  * 
  * @param Solar_Uri_Action|string $spec The URI to redirect to.
  * 
  * @param int|string $code The HTTP status code to redirect with; default
  * is '302 Found'.
  * 
  * @return void
  * 
  */
 public function redirect($spec, $code = '302')
 {
     if ($spec instanceof Solar_Uri_Action) {
         $href = $spec->get(true);
     } elseif (strpos($spec, '://') !== false) {
         // external link, protect against header injections
         $href = str_replace(array("\r", "\n"), '', $spec);
     } else {
         $uri = Solar::factory('Solar_Uri_Action');
         $href = $uri->quick($spec, true);
     }
     // kill off all output buffers
     while (@ob_end_clean()) {
     }
     // make sure there's actually an href
     $href = trim($href);
     if (!$href) {
         throw $this->_exception('ERR_REDIRECT_FAILED', array('href' => $href));
     }
     // set the status code
     $this->setStatusCode($code);
     // set the redirect location
     $this->setHeader('Location', $href);
     // clear the response body
     $this->content = null;
     // is this a GET-after-(POST|PUT) redirect?
     $request = Solar_Registry::get('request');
     if ($request->isPost() || $request->isPut()) {
         // tell the next request object that it's a get-after-post
         $session = Solar::factory('Solar_Session', array('class' => get_class($request)));
         $session->setFlash('is_gap', true);
     }
     // save the session
     session_write_close();
     // send the response directly -- done.
     $this->display();
 }