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.8 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.8
      • 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
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper
  • None

Classes

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