public static function redirect($target, $status_code = 302, $loops = NULL) {
        if(!$loops) {
            $loops = Loops::getCurrentLoops();
        }

        $config   = $loops->getService("config");
        $request  = $loops->getService("request");
        $response = $loops->getService("response");
        $core     = $loops->getService("web_core");

        if($target instanceof ElementInterface) {
            $target = $core->base_url.$target->getPagePath();
        }

        if(!is_string($target)) {
            throw new Exception("Target must be string or implement 'Loops\ElementInterface'.");
        }

        $response->addHeader("Location: ".$target.$request->getQuery());

        return $status_code;
    }
public static function redirect($target, $status_code = 302, $loops = NULL) {
        if(!$loops) {
            $loops = Loops::getCurrentLoops();
        }

        $config   = $loops->getService("config");
        $request  = $loops->getService("request");
        $response = $loops->getService("response");
        $core     = $loops->getService("web_core");

        if($target instanceof ElementInterface) {
            $target = $core->base_url.$target->getPagePath();
        }

        if(!is_string($target)) {
            throw new Exception("Target must be string or implement 'Loops\ElementInterface'.");
        }

        $response->addHeader("Location: ".$target.$request->getQuery());

        return $status_code;
    }
public static function redirect ( $ target , $ status_code = 302 , $ loops = NULL ) { if ( ! $ loops ) { $ loops = Loops :: getCurrentLoops ( ) ; } $ config = $ loops -> getService ( "config" ) ; $ request = $ loops -> getService ( "request" ) ; $ response = $ loops -> getService ( "response" ) ; $ core = $ loops -> getService ( "web_core" ) ; if ( $ target instanceof ElementInterface ) { $ target = $ core -> base_url . $ target -> getPagePath ( ) ; } if ( ! is_string ( $ target ) ) { throw new Exception ( "Target must be string or implement 'Loops\ElementInterface'." ) ; } $ response -> addHeader ( "Location: " . $ target . $ request -> getQuery ( ) ) ; return $ status_code ; }
Sets up redirect headers in the response

This function returns the desired http status code and thus can be conveniently use.
If a loops element is passed, the page path of that element will be used for redirection.

<code>
use Loops\Misc;
...
public function action($parameter) {
return Misc::redirect("http://www.example.com")
}
</code>

<code>
use Loops\Misc;
...
public function action($parameter) {
return Misc::redirect($this)
}
</code>

@param string|object $target The location as a string or a loops element
@param integer $status_code The status code for this redirection, defaults to 302 - Temporary redirect
@param Loops $loops An alternate Loops context if the default one should not be used
@return integer The passed status code
Sets up redirect headers in the response