CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.1 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeRoute
  • PluginShortRoute
  • RedirectRoute
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * Redistributions of files must retain the above copyright notice.
  8:  *
  9:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 10:  * @link          http://cakephp.org CakePHP(tm) Project
 11:  * @package       Cake.Routing.Route
 12:  * @since         CakePHP(tm) v 2.0
 13:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 14:  */
 15: 
 16: App::uses('CakeResponse', 'Network');
 17: App::uses('CakeRoute', 'Routing/Route');
 18: 
 19: /**
 20:  * Redirect route will perform an immediate redirect. Redirect routes
 21:  * are useful when you want to have Routing layer redirects occur in your
 22:  * application, for when URLs move.
 23:  *
 24:  * @package Cake.Routing.Route
 25:  */
 26: class RedirectRoute extends CakeRoute {
 27: 
 28: /**
 29:  * A CakeResponse object
 30:  *
 31:  * @var CakeResponse
 32:  */
 33:     public $response = null;
 34: 
 35: /**
 36:  * The location to redirect to. Either a string or a cake array url.
 37:  *
 38:  * @var mixed
 39:  */
 40:     public $redirect;
 41: 
 42: /**
 43:  * Flag for disabling exit() when this route parses a url.
 44:  *
 45:  * @var boolean
 46:  */
 47:     public $stop = true;
 48: 
 49: /**
 50:  * Constructor
 51:  *
 52:  * @param string $template Template string with parameter placeholders
 53:  * @param array $defaults Array of defaults for the route.
 54:  * @param array $options Array of additional options for the Route
 55:  */
 56:     public function __construct($template, $defaults = array(), $options = array()) {
 57:         parent::__construct($template, $defaults, $options);
 58:         $this->redirect = (array)$defaults;
 59:     }
 60: 
 61: /**
 62:  * Parses a string url into an array. Parsed urls will result in an automatic
 63:  * redirection
 64:  *
 65:  * @param string $url The url to parse
 66:  * @return boolean False on failure
 67:  */
 68:     public function parse($url) {
 69:         $params = parent::parse($url);
 70:         if (!$params) {
 71:             return false;
 72:         }
 73:         if (!$this->response) {
 74:             $this->response = new CakeResponse();
 75:         }
 76:         $redirect = $this->redirect;
 77:         if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) {
 78:             $redirect = $this->redirect[0];
 79:         }
 80:         if (isset($this->options['persist']) && is_array($redirect)) {
 81:             $redirect += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
 82:             $redirect = Router::reverse($redirect);
 83:         }
 84:         $status = 301;
 85:         if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
 86:             $status = $this->options['status'];
 87:         }
 88:         $this->response->header(array('Location' => Router::url($redirect, true)));
 89:         $this->response->statusCode($status);
 90:         $this->response->send();
 91:         $this->_stop();
 92:     }
 93: 
 94: /**
 95:  * There is no reverse routing redirection routes
 96:  *
 97:  * @param array $url Array of parameters to convert to a string.
 98:  * @return mixed either false or a string url.
 99:  */
100:     public function match($url) {
101:         return false;
102:     }
103: 
104: /**
105:  * Stop execution of the current script. Wraps exit() making
106:  * testing easier.
107:  *
108:  * @param integer|string $status see http://php.net/exit for values
109:  * @return void
110:  */
111:     protected function _stop($code = 0) {
112:         if ($this->stop) {
113:             exit($code);
114:         }
115:     }
116: 
117: }
118: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs