本文整理汇总了PHP中Base::reroute方法的典型用法代码示例。如果您正苦于以下问题:PHP Base::reroute方法的具体用法?PHP Base::reroute怎么用?PHP Base::reroute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base
的用法示例。
在下文中一共展示了Base::reroute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($event = 'before')
{
if (!isset($this->routes[$event])) {
return true;
}
foreach ($keys = array_keys($this->routes[$event]) as $key) {
$paths[] = str_replace('@', '*@', $key);
}
$vals = array_values($this->routes[$event]);
array_multisort($paths, SORT_DESC, $keys, $vals);
$this->routes[$event] = array_combine($keys, $vals);
// Convert to BASE-relative URL
$req = $this->f3->rel(urldecode($this->f3->URI));
foreach ($this->routes[$event] as $pattern => $routes) {
if (!($args = $this->f3->mask($pattern, $req))) {
continue;
}
ksort($args);
$route = NULL;
if (isset($routes[$ptr = $this->f3->AJAX + 1][$this->f3->VERB])) {
$route = $routes[$ptr];
} elseif (isset($routes[\Base::REQ_SYNC | \Base::REQ_AJAX])) {
$route = $routes[\Base::REQ_SYNC | \Base::REQ_AJAX];
}
if (!$route) {
continue;
}
if ($this->f3->VERB != 'OPTIONS' && isset($route[$this->f3->VERB])) {
$parts = parse_url($req);
if ($this->f3->VERB == 'GET' && preg_match('/.+\\/$/', $parts['path'])) {
$this->f3->reroute(substr($parts['path'], 0, -1) . (isset($parts['query']) ? '?' . $parts['query'] : ''));
}
$handler = $route[$this->f3->VERB][0];
if (is_bool(strpos($pattern, '/*'))) {
foreach (array_keys($args) as $key) {
if (is_numeric($key) && $key) {
unset($args[$key]);
}
}
}
if (is_string($handler)) {
// Replace route pattern tokens in handler if any
$handler = preg_replace_callback('/@(\\w+\\b)/', function ($id) use($args) {
return isset($args[$id[1]]) ? $args[$id[1]] : $id[0];
}, $handler);
if (preg_match('/(.+)\\h*(?:->|::)/', $handler, $match) && !class_exists($match[1])) {
$this->f3->error(500, 'PreRoute handler not found');
}
}
// Call route handler
return $this->f3->call($handler, array($this->f3, $args), 'beforeroute,afterroute') !== FALSE;
}
}
return true;
}
示例2: reroute
/**
* Language-aware reroute (autoprefix unnamed routes)
* @param string $url
* @param bool $permanent
* @return NULL
*/
function reroute($url = NULL, $permanent = FALSE)
{
if (preg_match('/^\\/([^\\/]*)/', $url, $m) && !array_key_exists($m[1], $this->languages)) {
$url = rtrim('/' . $this->current . $url, '/');
}
$this->f3->reroute($url, $permanent);
}
示例3: login
/**
* POST /login
* @param \Base $fw
* @return void
*/
public function login(\Base $fw)
{
if ($this->_getUser()) {
$fw->reroute('/dashboard');
}
$username = $fw->get('POST.username');
$password = $fw->get('POST.password');
$user = new \Model\User();
$user->load(array('username = ?', $username));
if ($user->id) {
if (password_verify($password, $user->password)) {
$fw->set('SESSION.user_id', $user->id);
$fw->reroute('/dashboard');
}
}
$fw->set('error', 'Invalid username or password.');
$this->_render('index.html');
}
示例4: authorize
/**
* AUTH Step 2: reroute to auth page
* @param null $callback_url
*/
public function authorize($callback_url = NULL)
{
$url = 'https://www.dropbox.com/1/oauth/authorize';
$params = array('oauth_token' => $this->authToken, 'locale ' => $this->f3->get('LANGUAGE'));
if ($callback_url) {
$params['oauth_callback'] = $callback_url;
}
$this->f3->reroute($url . '?' . http_build_query($params));
}
示例5: logout
/**
* GET|POST /logout
* @param \Base $fw
*/
function logout(\Base $fw)
{
if ($fw->get('COOKIE.session_token') == $fw->get('GET.session')) {
\Helper\Api\User::logout();
$fw->set('COOKIE.session_token', null);
$fw->reroute('/');
} else {
$fw->error(400);
}
}
示例6: show_question
function show_question(\Base $f3, $params)
{
$ans = $f3->get('GET.answer');
$rowid = $f3->get('GET.rowid');
$db = $f3->get('DB');
if ($rowid && $ans == "") {
$f3->reroute('/');
} else {
if ($ans && $rowid) {
$f3->dump($rowid);
$res = $db->exec('UPDATE q SET answer = ? WHERE rowid = ?', array($ans, $rowid));
$f3->reroute('/');
} else {
$res = $db->exec("SELECT rowid, * FROM q WHERE answer = '' ORDER BY random() LIMIT 1", $txt);
$f3->set('question', $res);
echo View::instance()->render('show_question.htm');
}
}
}
示例7: registerPost
/**
* POST /register
* @param \Base $fw
*/
function registerPost(\Base $fw)
{
try {
$token = \Helper\Api\User::register($fw->get('POST'));
$fw->set('COOKIE.session_token', $token);
$fw->reroute('/stream');
} catch (\Exception $e) {
$fw->set('error', $e->getMessage());
\App::error(403);
}
}
示例8: getSingle
/**
* @param \Base $f3
* @param array $params
* @return bool
*/
public function getSingle(\Base $f3, $params)
{
$this->response->data['SUBPART'] = 'comment_edit.html';
if (isset($params['id'])) {
$this->response->data['comment'] = $this->resource->load(array('_id = ?', $params['id']));
if (!$this->resource->dry()) {
return true;
}
}
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
$f3->reroute($f3->get('SESSION.LastPageURL'));
}
示例9: save
public function save(\Base $f3, $params)
{
$params = $this->parametric($params[1]);
if ($_SESSION['userID'] != 0 || \Base::instance()->get('CONFIG')['allow_guest_comment_news']) {
$errors = [];
$data = $f3->get('POST.comment');
// Obviously, there should be some text ...
if ("" == ($data['text'] = trim($data['text']))) {
$errors[] = 'MessageEmpty';
}
if ($_SESSION['userID']) {
if (empty($errors) and $this->model->saveComment($params['id'], $data, TRUE)) {
$f3->reroute('news/id=' . $params['id'], false);
} else {
$errors[] = "CannotSave";
}
} else {
// Check if captcha is initialized and matches user entry
if (empty($_SESSION['captcha']) or !password_verify(strtoupper($data['captcha']), $_SESSION['captcha'])) {
$errors[] = 'CaptchaMismatch';
}
// Guest can't post with an empty name
if ("" == ($data['name'] = trim($data['name']))) {
$errors[] = 'GuestNameEmpty';
}
// guest can't post URL (reg ex is not perfect, but it's a start)
if (preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $data['text'])) {
$errors[] = 'GuestURL';
}
if (empty($errors) and 1 == $this->model->saveComment($params['id'], $data)) {
// destroy this session captcha
unset($_SESSION['captcha']);
$f3->reroute('news/id=' . $params['id'], false);
}
}
// If no data was saved, we end up here, so we show the page again and it will display the errors
$f3->set('formError', $errors);
$this->index($f3, $params);
}
}
示例10: save
public function save(\Base $f3, $params)
{
if (empty($params['module'])) {
$f3->reroute('/adminCP/settings', false);
exit;
}
if (isset($_POST['form_data'])) {
// Save data from the generic created forms
$results = $this->model->saveKeys($f3->get('POST.form_data'));
} else {
// Sava data from special forms (language, layout)
$results = $this->saveData($f3, $params);
}
$this->index($f3, $params, $results);
}
示例11: delete
public function delete(\Base $f3, $params)
{
$this->resource->reset();
$msg = \Flash::instance();
if (isset($params['id'])) {
$this->resource->load(array('_id = ?', $params['id']));
if ($f3->get('HOST') == 'ikkez.de' && !$this->resource->dry() && $this->resource->username == 'admin') {
$msg->addMessage("You are not allowed to delete the demo-admin", 'danger');
$f3->reroute('/admin/' . $params['module']);
return;
}
parent::delete($f3, $params);
}
$f3->reroute($f3->get('SESSION.LastPageURL'));
}
示例12: dashboardPost
/**
* POST /user/dashboard
*
* @param \Base $f3
*/
public function dashboardPost($f3)
{
$user = $f3->get("user_obj");
if ($f3->get("POST.action") == "add") {
$widgets = $user->option("dashboard");
foreach ($f3->get("POST.widgets") as $widget) {
$widgets["left"][] = $widget;
}
} else {
$widgets = json_decode($f3->get("POST.widgets"));
}
$user->option("dashboard", $widgets);
$user->save();
if ($f3->get("AJAX")) {
$this->_printJson($widgets);
} else {
$f3->reroute("/");
}
}
示例13: filter
public function filter(\Base $f3, $params)
{
if (empty($params['a'])) {
if (isset($COOKIE['redirect_seen'])) {
$params['a'] = $params['b'];
$params['b'] = $params['c'];
} else {
$params['c'] = urldecode($params['c']);
$f3->reroute("/redirect/{$params['b']}/{$params['c']}", false);
}
}
$query = explode("&", $params['b']);
foreach ($query as $q) {
$item = explode("=", $q);
$old_data[$item[0]] = $item[1];
}
// default: redirect to main page
$redirect = "/";
if ($params['a'] == "viewstory") {
if (isset($old_data['sid']) && is_numeric($old_data['sid'])) {
$redirect = "/story/read/" . $old_data['sid'];
if (isset($old_data['chapter']) && is_numeric($old_data['chapter'])) {
$redirect .= "," . $old_data['chapter'];
}
}
} elseif ($params['a'] == "viewuser") {
if (isset($old_data['uid']) && is_numeric($old_data['uid'])) {
$redirect = "/authors/" . $old_data['uid'];
}
} elseif ($params['a'] == "browse") {
print_r($old_data);
// Browse is best handled by a search type
$redirect = "/story/search";
if (isset($old_data['type']) and $old_data['type'] == "categories") {
if (isset($old_data['catid']) && is_numeric($old_data['catid'])) {
$parameters[] = "category=" . $old_data['catid'];
}
/*
Tags (former classes), type by type
*/
/*
serious to-do
- load tag_groups.label ( classtype name ) without characters
- check $old_data[$label] and find in tags
*/
/* convert offset to page number */
if (isset($old_data['offset']) && is_numeric($old_data['offset'])) {
$items = \Config::instance()->stories_per_page;
$parameters[] = "page=" . (int) ($old_data['offset'] / $items);
}
} elseif (isset($old_data['type']) and $old_data['type'] == "class") {
if (isset($old_data['classid']) && is_numeric($old_data['classid'])) {
$tags[] = $old_data['classid'];
}
} elseif (isset($old_data['type']) and $old_data['type'] == "characters") {
if (isset($old_data['charid']) && is_numeric($old_data['charid'])) {
$c = $old_data['charid'];
// load tag with old character id from database
}
$tags[] = $old_data['charid'];
}
if (isset($tags)) {
$parameters[] = "tagIn=" . implode(",", $tags);
}
if (isset($parameters)) {
$redirect .= "/" . implode(";", $parameters);
}
} elseif ($params['a'] == "viewpage") {
$page = explode("=", $params['b']);
$redirect = "/page/" . @$page[1];
}
if (isset($COOKIE['redirect_seen'])) {
$f3->reroute($redirect, false);
} else {
$this->buffer(\View\Redirect::inform($redirect));
}
}
示例14: sprint_edit
/**
* @param \Base $f3
* @param array $params
* @throws \Exception
*/
public function sprint_edit($f3, $params)
{
$f3->set("title", $f3->get("dict.sprints"));
$sprint = new \Model\Sprint();
$sprint->load($params["id"]);
if (!$sprint->id) {
$f3->error(404);
return;
}
if ($post = $f3->get("POST")) {
if (empty($post["start_date"]) || empty($post["end_date"])) {
$f3->set("error", "Start and end date are required");
$this->_render("admin/sprints/edit.html");
return;
}
$start = strtotime($post["start_date"]);
$end = strtotime($post["end_date"]);
if ($end <= $start) {
$f3->set("error", "End date must be after start date");
$this->_render("admin/sprints/edit.html");
return;
}
$sprint->name = trim($post["name"]);
$sprint->start_date = date("Y-m-d", $start);
$sprint->end_date = date("Y-m-d", $end);
$sprint->save();
$f3->reroute("/admin/sprints");
return;
}
$f3->set("sprint", $sprint);
$this->_render("admin/sprints/edit.html");
}
示例15: preview
/**
* @param \Base $f3
* @param array $params
* @throws \Exception
*/
public function preview($f3, $params)
{
$file = new \Model\Issue\File();
$file->load($params["id"]);
if (!$file->id || !is_file($file->disk_filename)) {
$f3->error(404);
return;
}
if (substr($file->content_type, 0, 5) == "image" || $file->content_type == "text/plain") {
$this->_sendFile($file->disk_filename, $file->content_type, null, false);
return;
}
if ($file->content_type == "text/csv" || $file->content_type == "text/tsv") {
$delimiter = ",";
if ($file->content_type == "text/tsv") {
$delimiter = "\t";
}
$f3->set("file", $file);
$f3->set("delimiter", $delimiter);
$this->_render("issues/file/preview/table.html");
return;
}
$f3->reroute("/files/{$file->id}/{$file->filename}");
}