本文整理汇总了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'));
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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+']);