/** * Redirects as the request response. If the URL does not include a * protocol, it will be converted into a complete URL. * * Example: * ~~~ * $request->redirect($url); * ~~~ * * [!!] No further processing can be done after this method is called! * * @param string $url Redirect location * @param integer $code Status code: 301, 302, etc * @return void * @uses URL::site * @uses Request::send_headers */ public function redirect($url = '', $code = 302) { $referrer = $this->uri(); if (strpos($referrer, '://') === FALSE) { $referrer = URL::site($referrer, TRUE, Kohana::$index_file); } if (strpos($url, '://') === FALSE) { // Make the URI into a URL $url = URL::site($url, TRUE, Kohana::$index_file); } // Check whether the current request is ajax request if ($this->is_ajax()) { self::$redirect_url = $url; // Stop execution return; } if (($response = $this->response()) === NULL) { $response = $this->create_response(); } echo $response->status($code)->headers('Location', $url)->headers('Referer', $referrer)->send_headers()->body(); // Stop execution exit; }