日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php symfony urlmatcher-gt;match,symfony路由组件(The Routing Component)

發布時間:2023/12/4 php 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php symfony urlmatcher-gt;match,symfony路由组件(The Routing Component) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

The Routing component 把HTTP request轉換為一系列的配置參數.

安裝

你有兩種方式來安裝這個組件:通過 Composer (symfony/routing on Packagist);

使用官方的 Git repository (https://github.com/symfony/Routing)。

然后, 需要Composer把vendor/autoload.php 這個文件提供 給 autoloading mechanism 。 否則,你的應用程序將找不到這個組件。

用法

你需要下面三部分來設置基本的路由系統:RouteCollection, 包含路由的定義(instances of the class Route)

RequestContext, 有關request的信息;

UrlMatcher, 把request匹配成單一的route(即確定需要使用那個route)

下面有個簡單的例子。這里你需要確定你的autoloader 已經加載了這個組件:useSymfony\Component\Routing\Matcher\UrlMatcher;

useSymfony\Component\Routing\RequestContext;

useSymfony\Component\Routing\RouteCollection;

useSymfony\Component\Routing\Route;

$route = new Route('/foo', array('controller' => 'MyController'));

$routes = new RouteCollection();

$routes->add('route_name', $route);

$context = new RequestContext($_SERVER['REQUEST_URI']);

$matcher = new UrlMatcher($routes, $context);

$parameters = $matcher->match('/foo');

// array('controller' => 'MyController', '_route' => 'route_name')

需要注意的是當使用$_SERVER[‘REQUEST_URI’]時,在URL上面可以包含任何參數。一個簡單的解決辦法就是使用HttpFoundation component 這個組件,下文將會解釋這個組件。

未完待續

原文鏈接:

http://symfony.com/doc/current/components/routing/introduction.html

以上就介紹了symfony路由組件(The Routing Component),包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

總結

以上是生活随笔為你收集整理的php symfony urlmatcher-gt;match,symfony路由组件(The Routing Component)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。