当前位置: 首页>>代码示例>>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;未经允许,请勿转载。