当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::redirect方法代码示例

本文整理汇总了PHP中Slim::redirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::redirect方法的具体用法?PHP Slim::redirect怎么用?PHP Slim::redirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim的用法示例。


在下文中一共展示了Slim::redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPackage

 /**
  * @param string $repositoryName
  * @param string $packageName
  * @return \Composer\Package\PackageInterface
  */
 public function getPackage($repositoryName, $packageName)
 {
     $repository = $this->getRepository($repositoryName);
     $packages = $repository->findPackages($packageName);
     if (!$packages) {
         $this->app->redirect(ROOTURL . '/' . $repositoryName);
     }
     return array_shift($packages);
 }
开发者ID:researchgate,项目名称:broker,代码行数:14,代码来源:Application.php

示例2: authuser

function authuser($role = 'member')
{
    $user = User::fetchFromDatabaseSomehow();
    if ($user->belongsToRole($role) === false) {
        Slim::flash('error', 'Login required');
        Slim::redirect('/login');
    }
}
开发者ID:inscriptionweb,项目名称:lebonmail,代码行数:8,代码来源:helpers.php

示例3: Slim

ActiveRecord\Config::initialize(function ($cfg) {
    $cfg->set_model_directory('models');
    $cfg->set_connections(array('development' => 'mysql://test:test@127.0.0.1/test'));
});
$app = new Slim();
$app->get('/', function () use($app) {
    $data['tasks'] = Task::find('all');
    $app->render('task/index.php', $data);
})->name('tasks');
$app->post('/task/new/', function () use($app) {
    $task = new Task();
    $task->name = "My New Task";
    $task->done = 0;
    $task->save();
    if ($task->id > 0) {
        $app->redirect($app->urlFor('tasks'));
    }
})->name('task_new');
$app->get('/task/:id/edit', function ($id) use($app) {
    $data['task'] = Task::find($id);
    $app->render('task/edit.php', $data);
})->name('task_edit');
$app->post('/task/:id/edit', function ($id) use($app) {
    $task = Task::find($id);
    $task->name = $app->request()->post('name');
    $task->done = $app->request()->post('done') === '1' ? 1 : 0;
    $task->save();
    if ($task->id > 0) {
        $app->redirect($app->urlFor('tasks'));
    }
})->name('task_edit_post');
开发者ID:kxopa,项目名称:slimactiverecord,代码行数:31,代码来源:index.php

示例4: testSlimRedirectFails

 /**
  * Test Slim::redirect fails if status is not 301 or 302
  *
  * Pre-conditions:
  * You have initialized a Slim application with an accessible route.
  * The route attempts to redirect with an invalid HTTP status code.
  *
  * Post-conditions:
  * Slim throws an InvalidArgumentException which is caught by
  * the Slim::run dispatch loop, and the Response status is set to 500.
  */
 public function testSlimRedirectFails()
 {
     Slim::init();
     Slim::get('/', function () {
         Slim::redirect('/foo', 400);
     });
     Slim::run();
     $this->assertEquals(Slim::response()->status(), 500);
 }
开发者ID:kolanos,项目名称:Slim,代码行数:20,代码来源:SlimTest.php

示例5: testRedirect

 /**
  * Test redirect sets status and header
  */
 public function testRedirect()
 {
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         echo "Foo";
         //<-- Should not be in response body!
         $s->redirect('/somewhere/else', 303);
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals(303, $status);
     $this->assertEquals('/somewhere/else', $header['Location']);
     $this->assertEquals('/somewhere/else', $body);
 }
开发者ID:rs3d,项目名称:Slimplr,代码行数:17,代码来源:SlimTest.php

示例6: Slim

<?php

require_once 'Views/Twig/Autoloader.php';
Twig_Autoloader::register();
require 'Slim/Slim.php';
require 'Views/TwigView.php';
require 'lib/database.php';
$app = new Slim(array('view' => 'TwigView', 'http.version' => '1.0'));
$app->get('/', function () use($app) {
    $app->redirect('wishlist');
});
$app->get('/wishlist(/:order)', function ($order = 'year') use($app) {
    $app->etag('wishlist');
    $albums = Database::getAlbums('wishlist', $order);
    $data = array('albums' => $albums, 'page' => 'wishlist', 'order' => $order);
    $app->render('index.html', $data);
});
$app->get('/coleccao(/:order)', function ($order = 'year') use($app) {
    $app->etag('coleccao');
    $albums = Database::getAlbums('collection', $order);
    $data = array('albums' => $albums, 'page' => 'coleccao', 'order' => $order);
    $app->render('index.html', $data);
});
$app->run();
开发者ID:nelsonr,项目名称:Music-Albums-Collection,代码行数:24,代码来源:index.php

示例7: array

    // render the main page
    $blog->render('index.html', array('posts' => $posts_limit, 'page_current' => 1, 'page_count' => $pages_number));
});
// about page
$blog->get('/about', function () use($blog) {
    // render the about page
    $blog->render('about.html');
});
// projects page
$blog->get('/projects', function () use($blog) {
    // render the blog page
    $blog->render('projects.html');
});
// redirect blog/page1 to root index
$blog->get('/blog/1', function () use($blog) {
    $blog->redirect('/');
});
// blog pagination
$blog->get('/blog/:number', function ($number) use($blog, $getMarkdownPosts) {
    // get our posts
    $posts = $getMarkdownPosts($blog->config('posts.path'));
    // determine the start position of the array
    $previous_page = $number - 1;
    $start_index = $previous_page * $blog->config('pagination');
    // limit our posts to pagination
    $posts_limit = array_slice($posts, $start_index, $blog->config('pagination'));
    // get the total number of posts
    $posts_count = count($posts);
    // calculate the number of page
    $pages_number = ceil($posts_count / $blog->config('pagination'));
    // if the requested page is too high, 401
开发者ID:ngangchill,项目名称:stevenschobert.com,代码行数:31,代码来源:index.php

示例8: catch

            $cl_scraper->initialize($_POST['include']);
            echo $cl_scraper;
            exit;
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
});
$app->get('/site/:site', function ($site) use($app, $sites) {
    $init = true;
    $loadConfiguration = "findjobs.locations.xml";
    if (isset($sites[$site])) {
        $loadConfiguration = "{$site}.locations.xml";
        $sites[$site] = true;
    } else {
        $app->redirect('/');
    }
    try {
        require 'lib/CraigListScraper.class.php';
        $cl_scraper = new CraigListScraper("sites/{$loadConfiguration}");
        $title = $cl_scraper->getInfo()->title;
        require 'templates/index.php';
    } catch (Exception $e) {
        echo $e->getMessage();
    }
});
$app->get('/site/:site/data', function ($site) use($app, $sites) {
    $init = true;
    $loadConfiguration = "findjobs.locations.xml";
    if (isset($sites[$site])) {
        $loadConfiguration = "{$site}.locations.xml";
开发者ID:robertkraig,项目名称:Craigslist-Aggregator,代码行数:31,代码来源:index.php

示例9: function

                    $params['user_name'] = $user->first_name . ' ' . $user->last_name;
                    $params['button'] = "Logout";
                }
            }
        } else {
            if ($app->request()->get('error') == 'access_denied') {
                $params['errors'][] = "Access Denied";
            }
        }
    }
    $params['oauth_link'] = App::getOauthLink();
    $app->render('app.tpl', $params);
})->via('GET', 'POST');
$app->get('/logout/', function () use($app) {
    App::end();
    $app->redirect("/");
});
$app->get('/events/', 'authenticate', function () use($app) {
    $params = App::start();
    $params['title'] = "Events";
    $params['page'] = "events";
    $params['button'] = "Logout";
    $params['errors'] = array();
    try {
        $params['events'] = App::client()->user_list_events(array('event_statuses' => 'live,started'))->events;
    } catch (Exception $e) {
        $params['events'] = array();
    }
    $app->render('app.tpl', $params);
});
$app->map('/event/:id/(:tool)', 'authenticate', function ($id, $tool = null) use($app) {
开发者ID:ryanj,项目名称:The-Event-Day,代码行数:31,代码来源:index.php

示例10: array

    return $app->render('admin_home.html', array('articles' => $articles));
});
// Admin Add.
$app->get('/admin/add', $authCheck, function () use($app) {
    return $app->render('admin_input.html', array('action_name' => 'Add', 'action_url' => '/microframework/admin/add'));
});
// Admin Add - POST.
$app->post('/admin/add', $authCheck, function () use($app) {
    $article = Model::factory('Article')->create();
    $article->title = $app->request()->post('title');
    $article->author = $app->request()->post('author');
    $article->summary = $app->request()->post('summary');
    $article->content = $app->request()->post('content');
    $article->timestamp = date('Y-m-d H:i:s');
    $article->save();
    $app->redirect('/microframework/admin');
});
// Admin Edit.
$app->get('/admin/edit/(:id)', $authCheck, function ($id) use($app) {
    $article = Model::factory('Article')->find_one($id);
    if (!$article instanceof Article) {
        $app->notFound();
    }
    return $app->render('admin_input.html', array('action_name' => 'Edit', 'action_url' => '/microframework/admin/edit/' . $id, 'article' => $article));
});
// Admin Edit - POST.
$app->post('/admin/edit/(:id)', $authCheck, function ($id) use($app) {
    $article = Model::factory('Article')->find_one($id);
    if (!$article instanceof Article) {
        $app->notFound();
    }
开发者ID:rogeriopradoj,项目名称:tuto-micro_slim,代码行数:31,代码来源:index.php

示例11: Slim

 * @var Slim
 */
$app = new Slim(array('templates.path' => TEMPLATE_PATH));
/**
 * Add a middleware to all routes. Adding commonly accessed variables to the
 * view.
 */
$app->add(new puny\helpers\ViewHelper());
/** 
 * This is a Slim middleware route that prevents non logged in visitors to
 * access that route
 */
$locked = function () use($app) {
    return function () use($app) {
        if (!puny\User::is_logged_in()) {
            $app->redirect($app->urlFor('login'));
        }
    };
};
/**
 * This is the index page
 */
$app->get('/', function () use($app) {
    $posts = puny\Blog::get_posts(5);
    $app->render('home.php', array('posts' => $posts));
})->name('index');
/**
 * Show a single post
 */
$app->get('/blog/:url', function ($url) use($app) {
    $blog = new puny\Blog('posts/');
开发者ID:stojg,项目名称:puny,代码行数:31,代码来源:index.php

示例12: testSlimFlashWithRedirect

 /**
  * Slim Flash with Redirect
  *
  * Pre-conditions:
  * Slim app sets Flash message for next request;
  * Slim app halts with 302 redirect
  *
  * Post-conditions:
  * Message is persisted to $_SESSION after app is run;
  */
 public function testSlimFlashWithRedirect()
 {
     $app = new Slim();
     $app->get('/', function () use($app) {
         $app->flash('info', 'Foo redirect');
         $app->redirect('/foo');
     });
     $app->run();
     $this->assertArrayHasKey('info', $_SESSION['flash']);
     $this->assertEquals('Foo redirect', $_SESSION['flash']['info']);
 }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:21,代码来源:SlimTest.php

示例13: Slim

// Models
require 'models/Article.php';
require 'models/User.php';
// Configuration
TwigView::$twigDirectory = __DIR__ . '/Twig/lib/Twig/';
ORM::configure('mysql:host=localhost;dbname=blog');
ORM::configure('username', 'root');
ORM::configure('password', '');
// Start Slim.
$app = new Slim(array('view' => new TwigView()));
// Blog Homepage.
$app->get('/', function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    $isLoginned = User::isLoginned();
    if ($isLoginned) {
        return $app->redirect('/newtest/user/' . $_COOKIE['login']);
    } else {
        return $app->redirect('/newtest/feed');
    }
});
// Blog Feed.
$app->get('/feed', function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    $isLoginned = User::isLoginned();
    $user_name = '';
    if ($isLoginned) {
        $user_name = $_COOKIE['login'];
    }
    return $app->render('blog_home.html', array('articles' => $articles, 'isLoginned' => $isLoginned, 'B_author' => 'People', 'User_name' => $user_name));
});
// Blog View.
开发者ID:Nerbeer,项目名称:Slim_blog,代码行数:31,代码来源:index.php

示例14: function

// End FILTERS
/* == *
 *
 * ROUTES
 *
 * ==============================================*/
$app->map('/', function () use($app) {
    if ($app->request()->isPost() && sizeof($app->request()->post()) == 2) {
        // if valid login, set auth cookie and redirect
        $testp = sha1('uAX8+Tdv23/3YQ==');
        $post = (object) $app->request()->post();
        if (isset($post->username) && isset($post->password) && sha1($post->password) == $testp && $post->username == 'bppenne') {
            //$app->setEncryptedCookie('bppasscook', $post->password, 0);
            $app->setCookie('user_cook', $post->username, 0);
            $app->setCookie('pass_cook', $post->password, 0);
            $app->redirect('./review');
        } else {
            $app->redirect('.');
        }
    }
    $app->render('login.html');
})->via('GET', 'POST')->name('login');
$authUser = function ($role = 'member') use($app) {
    return function () use($role) {
        $app = Slim::getInstance();
        // Check for password in the cookie
        if ($app->getCookie('pass_cook') != 'uAX8+Tdv23/3YQ==' || $app->getCookie('user_cook') != 'bppenne') {
            //if ( $app->getEncryptedCookie('bppasscook', false) != 'uAX8+Tdv23/3YQ==') {
            $app->redirect('..');
            //$app->redirect('review');
        }
开发者ID:nerdfiles,项目名称:slim_bp,代码行数:31,代码来源:index.php

示例15: testSlimRedirect

 /**
  * Test Slim::redirect
  *
  * Pre-conditions:
  * Case A: Status code is less than 300
  * Case B: Status code is greater than 307
  * Case C: Status code is 300
  * Case D: Status code is 302 (between 300 and 307)
  * Case E: Status code is 307
  *
  * Post-conditions:
  * Case A: Response code is 500 (due to invalid redirect status)
  * Case B: Response code is 500 (due to invalid redirect status)
  * Case C: Response code is 300
  * Case D: Response code is 302
  * Case E: Response code is 307
  */
 public function testSlimRedirect()
 {
     //Case A
     $app1 = new Slim();
     $app1->get('/', function () use($app1) {
         $app1->redirect('/foo', 200);
     });
     ob_start();
     $app1->run();
     $app1Out = ob_get_clean();
     $this->assertEquals(500, $app1->response()->status());
     //Case B
     $app2 = new Slim();
     $app2->get('/', function () use($app2) {
         $app2->redirect('/foo', 308);
     });
     ob_start();
     $app2->run();
     $app2Out = ob_get_clean();
     $this->assertEquals(500, $app2->response()->status());
     //Case C
     $app3 = new Slim();
     $app3->get('/', function () use($app3) {
         $app3->redirect('/foo', 300);
     });
     $app3->run();
     $this->assertEquals(300, $app3->response()->status());
     //Case D
     $app4 = new Slim();
     $app4->get('/', function () use($app4) {
         $app4->redirect('/foo', 302);
     });
     $app4->run();
     $this->assertEquals(302, $app4->response()->status());
     //Case E
     $app5 = new Slim();
     $app5->get('/', function () use($app5) {
         $app5->redirect('/foo', 307);
     });
     $app5->run();
     $this->assertEquals(307, $app5->response()->status());
 }
开发者ID:inscriptionweb,项目名称:lebonmail,代码行数:59,代码来源:SlimTest.php


注:本文中的Slim::redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。