Router::redirect PHP Method

redirect() public static method

Redirection routes are different from normal routes as they perform an actual header redirection if a match is found. The redirection can occur within your application or redirect to an outside location. Examples: Router::redirect('/home/*', array('controller' => 'posts', 'action' => 'view'), array('persist' => true)); Redirects /home/* to /posts/view and passes the parameters to /posts/view. Using an array as the redirect destination allows you to use other routes to define where a URL string should be redirected to. Router::redirect('/posts/*', 'http://google.com', array('status' => 302)); Redirects /posts/* to http://google.com with a HTTP status of 302 ### Options: - status Sets the HTTP status (default 301) - persist Passes the params to the redirected route, if it can. This is useful with greedy routes, routes that end in * are greedy. As you can remap URLs and not loose any passed/named args.
See also: routes
public static redirect ( string $route, array $url, array $options = [] ) : array
$route string A string describing the template of the route
$url array A URL to redirect to. Can be a string or a CakePHP array-based URL
$options array An array matching the named elements in the route to regular expressions which that element should match. Also contains additional parameters such as which routed parameters should be shifted into the passed arguments. As well as supplying patterns for routing parameters.
return array Array of routes
    public static function redirect($route, $url, $options = array())
    {
        App::uses('RedirectRoute', 'Routing/Route');
        $options['routeClass'] = 'RedirectRoute';
        if (is_string($url)) {
            $url = array('redirect' => $url);
        }
        return static::connect($route, $url, $options);
    }

Usage Example

Exemplo n.º 1
0
 public function view()
 {
     config::set('heading', 'БЛОГ');
     $params = $this->getParams();
     if (isset($params[0])) {
         $alias = strtolower($params[0]);
         $this->data['one_blog'] = $this->model->getOneBlogWithComment($alias);
     }
     if ($_POST and isset($_POST['id_comm'])) {
         if (clearData($_POST['id_comm'])) {
             $id = clearData($_POST['id_comm']);
         } else {
             throw new Exception('Введены некорректные данные');
         }
         if (clearData($_POST['text-comm'])) {
             $text = clearData($_POST['text-comm'], true);
         } else {
             throw new Exception('Введены некорректные данные');
         }
         if (clearData($_POST['n_comm'])) {
             $name = clearData($_POST['n_comm']);
         } else {
             throw new Exception('Введены некорректные данные');
         }
         $tableUserId = Session::getSession('id') ? Session::getSession('id') : NULL;
         $this->model->addComment($id, $text, $name, $tableUserId);
         Router::redirect($_SERVER['REQUEST_URI']);
     }
 }
All Usage Examples Of Router::redirect