国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

CakePHP的重定向路由

2018-01-12 17:06 更新

當(dāng)我們想告知客戶端程序某個網(wǎng)址已被移動時,重定向路由是很有用的。可以使用以下函數(shù)進行URL重定向。

static CakeRoutingRouter::redirect($route, $url, $options =[])

上面的函數(shù)有三個參數(shù)-

  • 描述路由模板的字符串。

  • 一個要重定向到的URL。

  • 一個把路由中定名元素和元素所匹配的正則表達式相搭配的數(shù)組。

修改下圖所示的config/routes.php文件。這里,我們用到了先前創(chuàng)建的控制器。

config/routes.php文件

<?php
   use CakeCorePlugin;
   use CakeRoutingRouteBuilder;
   use CakeRoutingRouter;

   Router::defaultRouteClass('DashedRoute');
   Router::scope('/', function (RouteBuilder $routes) {
      $routes->connect('/generate2', ['controller' => 'Tests', 'action' => 'index']);
      $routes->redirect('/generate1','http://tutorialspoint.com/');
      $routes->connect('/generate_url',['controller'=>'Generates','action'=>'index']);
      $routes->fallbacks('DashedRoute');
   });
   Plugin::routes();

通過訪問以下URL執(zhí)行上面的例子。

  • URL 1 - HTTP://localhost:85/CakePHP/generate_url

  • URL 2 - HTTP://localhost:85/CakePHP/generate1

  • URL 3 - HTTP://localhost:85/CakePHP/generate2

URL 1輸出


URL 2輸出

你會被重定向到http://tutorialspoint.com

URL 3輸出



以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號