redirect() публичный статический Метод

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.
См. также: 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.
Результат array Array of routes
Пример #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']);
     }
 }
Пример #2
0
 public static function run($uri)
 {
     self::$router = new Router($uri);
     self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
     Lang::load(self::$router->getLanguage());
     $controller_class = ucfirst(self::$router->getController()) . "Controller";
     $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
     $layout = self::$router->getRoute();
     if ($layout == "admin" && Session::get("role") != "admin") {
         if ($controller_method != "admin_login") {
             Router::redirect("/admin/users/login");
         }
     }
     //Calling controller's method
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $view_path = $controller_object->{$controller_method}();
         $view_object = new View($controller_object->getData(), $view_path);
         $content = $view_object->render();
     } else {
         throw new Exception("Method {$controller_method} does not exist in {$controller_class}");
     }
     $layout_path = VIEWS_PATH . DS . $layout . ".html";
     $layout_view_object = new View(compact('content'), $layout_path);
     echo $layout_view_object->render();
 }
Пример #3
0
 /**
  * Displays a view
  *
  * @return void
  * @throws NotFoundException When the view file could not be found
  *	or MissingViewException in debug mode.
  */
 public function home()
 {
     // Redirect to tasks page
     Router::redirect('*', array('controller' => 'tasks', 'action' => 'index'));
     $path = func_get_args();
     $count = count($path);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $title_for_layout = Inflector::humanize($path[$count - 1]);
     }
     $this->set(compact('page', 'subpage', 'title_for_layout'));
     try {
         $this->render(implode('/', $path));
     } catch (MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new NotFoundException();
     }
 }
Пример #4
0
 public function p_signup()
 {
     # Check if data was entered
     if ($_POST['first_name'] == "" || $_POST['last_name'] == "" || $_POST['password'] == "") {
         # Send back to signup with appropriate error
         Router::redirect("/users/signup/Please enter all requested information");
     }
     # Check if email address is of the right form
     if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
         # Send back to signup with appropriate error
         Router::redirect("/users/signup/Please enter a valid email address");
     }
     # Check if passwords match
     if ($_POST['password'] != $_POST['password_check']) {
         # Send back to signup with appropriate error
         Router::redirect("/users/signup/Passwords do not match");
     }
     # Remove the password check from the array
     unset($_POST['password_check']);
     # Encrypt the password
     $_POST['password'] = sha1(PASSWORD_SALT . $_POST['password']);
     # More data we want stored with the user
     $_POST['created'] = Time::now();
     $_POST['modified'] = Time::now();
     $_POST['token'] = sha1(TOKEN_SALT . $_POST['email'] . Utils::generate_random_string());
     # Insert this user into the database
     $user_id = DB::instance(DB_NAME)->insert("users", $_POST);
     # Send the user to the signup success page
     $this->template->content = View::instance('v_users_signup_success');
     $this->template->title = "Success!";
     echo $this->template;
 }
Пример #5
0
 public function logout()
 {
     Load::lib('SdAuth');
     SdAuth::logout();
     View::template('login2');
     Router::redirect('');
 }
Пример #6
0
 function cerrar()
 {
     Auth::destroy_identity();
     Session::delete("usuario_id");
     Session::delete("usuario_nombrecompleto");
     Router::redirect("login/index");
 }
Пример #7
0
 public static function run($uri)
 {
     self::$router = new Router($uri);
     self::$db = DB::getInstance(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
     Lang::load(self::$router->getLanguage());
     $controller_class = ucfirst(self::$router->getController()) . 'controller';
     $controller_method = strtolower(self::$router->getMethod_prefix() . self::$router->getAction());
     $controller_parametr = self::$router->getParams();
     $layout = self::$router->getRoute();
     if ($layout == 'admin' && Session::get('role') != 'admin') {
         if ($controller_method != 'admin_login') {
             Router::redirect('/admin/users/login');
         }
     }
     //Calling conrollers method
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $view_path = $controller_object->{$controller_method}();
         $view_object = new View($controller_object->getData(), $view_path);
         $content = $view_object->render();
     } else {
         throw new Exception('Метод ' . $controller_method . ' в классе ' . $controller_class . 'не найден');
     }
     $layout_path = VIEW_PATH . DS . $layout . '.html';
     $layout_view_object = new View(compact('content'), $layout_path);
     // основной рендер вывода страниц
     echo $layout_view_object->render();
 }
Пример #8
0
 public function creerCommentaire($disc)
 {
     if (!empty($_POST)) {
         $this->executerRequete("INSERT INTO message (id_utilisateur, id_discussion, texte, date) VALUES (?,?,?,NOW())", [$_SESSION['auth']->id, $disc, $_POST['commentaire']]);
         Router::redirect("forumDiscussion", ['id' => $disc]);
     }
 }
 protected final function initialize()
 {
     $controller = Router::get("controller");
     $action = Router::get("action");
     $ruta = $controller . "/" . $action;
     $tipousuario = Auth::get("tipousuario");
     if (Auth::is_valid()) {
         if ($tipousuario == "alumno") {
             if ($ruta != "perfil/index" and $ruta != "perfil/logout" and $ruta != "asistencia/alumno") {
                 Flash::warning("Acceso Denegado");
                 Router::redirect("perfil/");
             }
         }
         if ($tipousuario == "docente") {
             $permisos = array("perfil/actualizar", "perfil/cambiarpass", "perfil/index", "perfil/programarevaluaciones", "calificar/grupo", "perfil/logout", "asistencia/index", "asistencia/agregar_asistencia");
             if (!in_array($ruta, $permisos)) {
                 Flash::warning("Acceso Denegado");
                 Router::redirect("perfil/");
             }
         }
     } else {
         if ($ruta != 'index/index' and $ruta != 'perfil/logout') {
             Flash::warning("Acceso Denegado");
             Router::redirect("index/index");
         }
     }
 }
Пример #10
0
 public static function run($uri)
 {
     self::$router = new Router($uri);
     # создаем обект базы данных и передаем параметры подключения
     self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
     Lang::load(self::$router->getLanguage());
     $controller_class = ucfirst(self::$router->getController()) . 'Controller';
     $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
     # при каждом запросе к руту admin выполняется проверка, имеет ли пользователь на это права
     $layout = self::$router->getRoute();
     if ($layout == 'admin' && Session::get('role') != 'admin') {
         if ($controller_method != 'admin_login') {
             Router::redirect('/admin/users/login');
         }
     }
     // Calling controller's method
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $view_path = $controller_object->{$controller_method}();
         $view_object = new View($controller_object->getData(), $view_path);
         $content = $view_object->render();
     } else {
         throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.');
     }
     # код віполняющий рендеринг
     $layout_path = VIEWS_PATH . DS . $layout . '.html';
     $layout_view_object = new View(compact('content'), $layout_path);
     echo $layout_view_object->render();
 }
 public function sala()
 {
     // http://gravatar.com/avatar/
     $this->title = 'Sala de Asistencia';
     if (Input::post("nombre") and Input::post("email") and Input::post("ayuda")) {
         $usuario = new Usuario();
         $usuario->nombre = Input::post("nombre");
         $usuario->email = Input::post("email");
         $usuario->online = 1;
         if ($usuario->save()) {
             $id = $usuario->find('columns: id', 'limit: 1', 'order: id desc');
             $canal = new Canal();
             $this->imagen = $this->get_gravatar($usuario->email);
             $imagen = "<img style='float:left;padding:4px;' src='" . $this->imagen . "' width=\"50\" alt=\"Tu Imagen\">";
             $canal->mensaje = "<span style='float:left;padding-top:10px;'>" . $imagen . "<b>" . $usuario->nombre . "(" . $usuario->email . ")</b>: <br>" . Input::post("ayuda") . "</span> <div class='clearfix'></div>";
             $canal->identificador_canal = md5(Input::post("email") . date("Y-m-d") . $id[0]->id);
             $canal->usuario_id = $id[0]->id;
             if ($canal->save()) {
                 $this->nombre = Input::post("nombre");
                 $this->email = Input::post("email");
                 $this->identificador_canal = $canal->identificador_canal;
                 $this->usuario_id = $canal->usuario_id;
             } else {
                 Flash::error("No se pudo abrir un canal de asistencia, Vuelva a intentarlo por favor!");
                 Router::redirect("index/chat");
             }
         } else {
             Flash::error("No pudo ingresar a una sala de asistencia, por favor intentelo de nuevo");
         }
     } else {
         Flash::error("El nombre, email y la consulta de como podemos ayudarte, son obligatorios");
         Router::redirect("index/chat");
     }
 }
Пример #12
0
 public function p_ticket()
 {
     # Sanitize the user input
     $_POST = DB::instance(DB_NAME)->sanitize($_POST);
     # Backup validation in case of javascript failure
     # Not recommended as the page looks terrible without js
     # Check if data was entered
     if ($_POST['name'] == "" || $_POST['phone'] == "" || $_POST['serial'] == "") {
         # Send back to signup with appropriate error
         Router::redirect("/tickets");
     }
     # Check if email address is of the right form
     if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
         # Send back to signup with appropriate error
         Router::redirect("/tickets");
     }
     # Unix timestamp of when this post was created / modified
     $_POST['ticket_id'] = date('Ymd\\-his');
     $_POST['created'] = Time::now();
     $_POST['modified'] = Time::now();
     # Add the location
     $_POST['location'] = 'Helpdesk';
     # Create ticket and computer arrays
     $ticket = $_POST;
     $computer = $_POST;
     # Add ticket status
     $ticket['status'] = 'New';
     # Remove the unneeded data before submit
     unset($ticket['model'], $ticket['serial']);
     unset($computer['email'], $computer['phone'], $computer['notes']);
     # Insert
     DB::instance(DB_NAME)->insert('tickets', $ticket);
     DB::instance(DB_NAME)->insert('computers', $computer);
     # Build a multi-dimension array of recipients of this email
     $to[] = array("name" => $_POST["name"], "email" => $_POST["email"]);
     # Build a single-dimension array of who this email is coming from
     # note it's using the constants we set in the configuration above)
     $from = array("name" => "HSPH Helpdesk", "email" => APP_EMAIL);
     # Subject
     $subject = "Helpdesk Computer Drop Off: " . $_POST["subject"];
     # Generate Time
     # You can set the body as just a string of text
     $body = "This is confirmation that you have delivered your " . $_POST['model'] . " with the serial number " . $_POST['serial'] . " to the helpdesk at " . date('g\\:i a \\o\\n F d\\, Y') . " with the following notes: <br>" . $_POST['notes'] . "<br><br>Thank you and have a great day!" . "<br>The Helpdesk<br>(617) 432-4357<br>helpdesk@hsph.harvard.edu";
     # OR, if your email is complex and involves HTML/CSS, you can build the body via a View just like we do in our controllers
     # $body = View::instance('e_users_welcome');
     # Why not send an email to the test account as well
     # Build multi-dimension arrays of name / email pairs for cc / bcc if you want to
     $cc = "";
     $bcc = "*****@*****.**";
     # With everything set, send the email
     if (!($email = Email::send($to, $from, $subject, $body, true, $cc, $bcc))) {
         echo "Mailer Error: " . $mail->ErrorInfo;
     } else {
         # Load the success page
         $this->template->content = View::instance('v_tickets_p_ticket_success');
         $this->template->title = "Success!";
         echo $this->template;
     }
 }
Пример #13
0
 public function markread()
 {
     Container::get('hooks')->fire('controller.index.markread');
     Auth::set_last_visit(User::get()->id, User::get()->logged);
     // Reset tracked topics
     Track::set_tracked_topics(null);
     return Router::redirect(Router::pathFor('home'), __('Mark read redirect'));
 }
Пример #14
0
 /**
  * Borra un Registro
  */
 public function borrar($id)
 {
     if (!Load::model($this->model)->delete((int) $id)) {
         Flash::error('Falló Operación');
     }
     //enrutando al index para listar los articulos
     Router::redirect();
 }
Пример #15
0
 public function unfollow($user_id_followed)
 {
     # Delete this connection
     $where_condition = 'WHERE user_id = ' . $this->user->user_id . ' AND user_id_followed = ' . $user_id_followed;
     DB::instance(DB_NAME)->delete('users_users', $where_condition);
     # Send them back
     Router::redirect("/posts/users");
 }
Пример #16
0
 public function admin_delete()
 {
     $params = App::getRouter()->getParams();
     if (isset($params[0])) {
         $this->model->eventDelete($params[0]);
         Router::redirect('/admin/events');
     }
 }
 protected function before_filter()
 {
     // Verificando si el rol del usuario actual tiene permisos para la acción a ejecutar
     if (!$this->acl->is_allowed($this->userRol, $this->controller_name, $this->action_name)) {
         Flash::error("Acceso negado");
         return Router::redirect("usuario/ingresar");
     }
 }
Пример #18
0
 /**
  * Contructeur
  */
 public function __construct()
 {
     parent::__construct();
     $this->view = 'login';
     if ($this->_session->is_logged()) {
         Router::redirect("/Users", "refresh");
     }
 }
Пример #19
0
 public function admin_add()
 {
     if ($_POST) {
         $posts = $_POST;
         $this->model->addNewPost($posts);
         Router::redirect('/admin/posts/index');
     }
 }
 public function logout()
 {
     if (Auth::is_valid()) {
         Auth::destroy_identity();
         Flash::valid("Sesión finalizada");
     }
     Router::redirect("/");
 }
Пример #21
0
 public function index()
 {
     if ($this->user) {
         Router::redirect("/users/home/");
     } else {
         Router::redirect("/users/anonymous_home/");
     }
 }
Пример #22
0
 public function admin_back()
 {
     if (Session::get('role') != 'admin') {
         Router::redirect('/');
     }
     if ($_POST['back']) {
         Router::redirect('/admin/allusers/');
     }
 }
Пример #23
0
 public function admin_back()
 {
     if (getId() == null) {
         Router::redirect('/');
     }
     if ($_POST['back']) {
         Router::redirect('/admin/contacts/');
     }
 }
Пример #24
0
 public function admin_back()
 {
     if (Session::get('id') == null) {
         Router::redirect('/');
     }
     if ($_POST['back']) {
         Router::redirect('/admin/contacts/');
     }
 }
Пример #25
0
 public function __invoke($request, $response, $next)
 {
     // Redirect user to home page if not admin
     if (User::get()->g_id != ForumEnv::get('FEATHER_ADMIN')) {
         return Router::redirect(Router::pathFor('home'), __('No permission'));
     }
     $response = $next($request, $response);
     return $response;
 }
Пример #26
0
 public static function load($lang_code)
 {
     $lang_file_path = ROOT . DS . 'lang' . DS . strtolower($lang_code) . '.php';
     if (file_exists($lang_file_path)) {
         self::$data = (include $lang_file_path);
     } else {
         Router::redirect('/static.html');
     }
 }
Пример #27
0
 public function warned()
 {
     if (!is_null(Session::get('person'))) {
         $this->model->deleteWarning(Session::get('person'));
     } else {
         Session::setFlash('Авторизуйтеся в системі');
     }
     Router::redirect('/personal');
 }
Пример #28
0
 /**
  * Fonction qui vérifie que l'utilisateur a le droit d'accéder au contenu
  * Sinon il est redirigé.
  * Seul l'administrateur peut accéder ici
  */
 public function authorization()
 {
     if (!$this->_session->is_logged()) {
         Router::redirect("/Login", "refresh");
     }
     $user = $this->_session->user;
     if (!$user->isAdmin()) {
         Router::redirect("/Users", "refresh");
     }
 }
Пример #29
0
 public function delete($id)
 {
     $role = Load::model("roles")->find($id);
     if ($role->delete()) {
         Flash::valid("role Eliminado");
     } else {
         Flash::error("No se elimino el role");
     }
     Router::redirect("roles/");
 }
Пример #30
-1
 public static function run($uri)
 {
     self::$router = new Router($uri);
     self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
     Lang::load(self::$router->getLanguage());
     $controller_class = ucfirst(self::$router->getController()) . 'Controller';
     $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
     $layout = self::$router->getRoute();
     if ($layout == 'user' && Session::get('role') != 'user') {
         if ($controller_method != 'login') {
             Router::redirect('/users/login');
         }
     } elseif ($layout == 'admin' && Session::get('role') != 'admin') {
         if ($controller_method != 'admin_login') {
             Router::redirect('/admin/users/login');
         }
     }
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $view_path = $controller_object->{$controller_method}();
         $view_object = new View($controller_object->getData(), $view_path);
         $content = $view_object->render();
     } else {
         throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.');
     }
     $layout_path = VIEWS_PATH . DS . $layout . '.html';
     $layout_view_object = new View(compact('content'), $layout_path);
     echo $layout_view_object->render();
 }