官术网_书友最值得收藏!

The URL

URLs in Drupal 8 are represented with the Drupal\Core\Url class, which has a number of static methods that allow you to create an instance. The most important of these is ::fromRoute(), which takes a route name, route parameters (if any are needed for that route), and an array of options to create a new instance of Url. There are other such methods available that turn all sorts of other things into a Url, most notably, the ::fromUri() method that takes in an internal or external URL. Sometimes, these methods are very helpful, especially when dealing with dynamically obtained data (such as a URL). However, when hardcoding, it's always best to work with route names because that allows you to later change the actual path behind that route without affecting your code.

There are many options that can be passed to the Url when creating it, inside the $options array. You can pass an array of query parameters, a fragment, and others. These will then help construct a URL as complex as you need without having to deal with strings yourself. I suggest that you check out the documentation above the ::fromUri() method because it describes them all. Also, keep in mind that the options are pretty much the same, regardless of the method that you use to create the Url object.

主站蜘蛛池模板: 彭州市| 烟台市| 永宁县| 冀州市| 新乡县| 襄汾县| 璧山县| 德惠市| 晴隆县| 元朗区| 东辽县| 新邵县| 北碚区| 塘沽区| 松原市| 宁波市| 浦城县| 衡南县| 太和县| 康马县| 搜索| 河东区| 中西区| 台州市| 兰西县| 大埔区| 隆昌县| 龙海市| 成安县| 佛冈县| 平原县| 张家川| 吉安县| 武安市| 怀来县| 古蔺县| 静乐县| 阆中市| 四子王旗| 井陉县| 瑞安市|