當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Router::redirect方法代碼示例

本文整理匯總了PHP中Cake\Routing\Router::redirect方法的典型用法代碼示例。如果您正苦於以下問題:PHP Router::redirect方法的具體用法?PHP Router::redirect怎麽用?PHP Router::redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Routing\Router的用法示例。


在下文中一共展示了Router::redirect方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testRedirectResponseWithHeaders

 public function testRedirectResponseWithHeaders()
 {
     Router::redirect('/testpath', '/pages');
     $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/testpath']);
     $response = new Response('php://memory', 200, ['X-testing' => 'Yes']);
     $next = function ($req, $res) {
     };
     $middleware = new RoutingMiddleware();
     $response = $middleware($request, $response, $next);
     $this->assertEquals(301, $response->getStatusCode());
     $this->assertEquals('http://localhost/pages', $response->getHeaderLine('Location'));
     $this->assertEquals('Yes', $response->getHeaderLine('X-testing'));
 }
開發者ID:markstory,項目名稱:cakephp-spekkoek,代碼行數:13,代碼來源:RoutingMiddlewareTest.php

示例2: testBeforeDispatchRedirectRoute

 /**
  * test setting parameters in beforeDispatch method
  *
  * @return void
  * @triggers __CLASS__ $this, compact(request)
  */
 public function testBeforeDispatchRedirectRoute()
 {
     Router::redirect('/home', ['controller' => 'articles']);
     Router::connect('/:controller/:action/*');
     $filter = new RoutingFilter();
     $request = new Request("/home");
     $response = new Response();
     $event = new Event(__CLASS__, $this, compact('request', 'response'));
     $response = $filter->beforeDispatch($event);
     $this->assertInstanceOf('Cake\\Network\\Response', $response);
     $this->assertSame('http://localhost/articles/index', $response->header()['Location']);
     $this->assertSame(301, $response->statusCode());
 }
開發者ID:jdaosavanh,項目名稱:clickerwebapp,代碼行數:19,代碼來源:RoutingFilterTest.php

示例3: testRouteRedirection

 /**
  * test setting redirect routes
  *
  * @return void
  */
 public function testRouteRedirection()
 {
     $routes = new RouteCollection();
     Router::setRouteCollection($routes);
     Router::redirect('/blog', array('controller' => 'posts'), array('status' => 302));
     Router::connect('/:controller', array('action' => 'index'));
     $this->assertEquals(2, count($routes));
     $routes->get(0)->response = $this->getMock('Cake\\Network\\Response', array('_sendHeader', 'stop'));
     $this->assertEquals(302, $routes->get(0)->options['status']);
     Router::parse('/blog');
     $header = $routes->get(0)->response->header();
     $this->assertEquals(Router::url('/posts', true), $header['Location']);
     $this->assertEquals(302, $routes->get(0)->response->statusCode());
     $routes->get(0)->response = $this->getMock('Cake\\Network\\Response', array('_sendHeader'));
     Router::parse('/not-a-match');
     $this->assertSame([], $routes->get(0)->response->header());
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:22,代碼來源:RouterTest.php

示例4: testRedirectWithAnotherRouteClass

 /**
  * Test that redirect() works with another route class.
  *
  * @return void
  */
 public function testRedirectWithAnotherRouteClass()
 {
     $route1 = $this->getMockBuilder('Cake\\Routing\\Route\\RedirectRoute')->setConstructorArgs(['/mobile\''])->getMock();
     $class = '\\' . get_class($route1);
     Router::redirect('/mobile', '/', ['status' => 301, 'routeClass' => $class]);
     $routes = Router::routes();
     $route = $routes[0];
     $this->assertInstanceOf($class, $route);
 }
開發者ID:rashmi,項目名稱:newrepo,代碼行數:14,代碼來源:RouterTest.php

示例5: testRedirect

 /**
  * Test that redirect() works.
  *
  * @return void
  */
 public function testRedirect()
 {
     Router::redirect('/mobile', '/', ['status' => 301]);
     $routes = Router::routes();
     $route = $routes[0];
     $this->assertInstanceOf('Cake\\Routing\\Route\\RedirectRoute', $route);
 }
開發者ID:alexunique0519,項目名稱:Blog_Cakephp_association,代碼行數:12,代碼來源:RouterTest.php

示例6: elseif

 */
Router::defaultRouteClass('Route');
Router::addUrlFilter(function ($params, $request) {
    if (isset($request->params['lang']) && !isset($params['lang'])) {
        $params['lang'] = $request->params['lang'];
    } elseif (!isset($params['lang'])) {
        $params['lang'] = Router::getRequest()->session()->read('lang');
        // set your default language here
    }
    return $params;
});
$lang = 'en';
if (Router::getRequest()->session()->check('Config.language')) {
    $lang = Router::getRequest()->session()->read('Config.language');
}
Router::redirect('/', "/{$lang}/");
Router::connect('/:lang/', ['controller' => 'Home', 'action' => 'index']);
Router::connect('/:lang/:controller', ['action' => 'index']);
Router::connect('/:lang/:controller/about', ['action' => 'about']);
Router::connect('/:lang/:controller/search', ['action' => 'search']);
Router::connect('/:lang/:controller/profile', ['action' => 'profile']);
Router::connect('/:lang/:controller/settings', ['action' => 'settings']);
Router::connect('/:lang/:controller/add', ['action' => 'add']);
Router::connect('/:lang/:controller/view/:id', ['action' => 'view'], ['id' => '\\d+', 'pass' => ['id']]);
Router::connect('/:lang/:controller/edit/:id', ['action' => 'edit'], ['id' => '\\d+', 'pass' => ['id']]);
Router::connect('/:lang/:controller/delete/:id', ['action' => 'delete'], ['id' => '\\d+', 'pass' => ['id']]);
Router::connect('/:lang/:controller/roledata_list/:id', ['action' => 'roledata_list'], ['id' => '\\d+', 'pass' => ['id']]);
Router::connect('/:lang/:controller/login', ['action' => 'login']);
Router::connect('/:lang/:controller/logout', ['action' => 'logout']);
Router::connect('/:lang/:controller/accountLog', ['action' => 'accountLog']);
Router::connect('/:lang/:controller/equipment_item/:id/:slug', ['action' => 'equipment_item'], ['pass' => ['id', 'slug'], 'id' => '\\d+']);
開發者ID:GreeNoir,項目名稱:game-wizard,代碼行數:31,代碼來源:routes.php


注:本文中的Cake\Routing\Router::redirect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。