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

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 which takes an internal or external URI. These methods can be very helpful, especially when dealing with dynamically obtained data. 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 Url when instantiating 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.

主站蜘蛛池模板: 万源市| 利辛县| 天全县| 理塘县| 海兴县| 鄂托克前旗| 武城县| 大厂| 杭锦后旗| 齐齐哈尔市| 洪雅县| 洛浦县| 扎囊县| 芒康县| 常德市| 筠连县| 姜堰市| 大丰市| 麟游县| 刚察县| 安顺市| 贡觉县| 洞头县| 卢龙县| 哈巴河县| 连南| 洪湖市| 扎鲁特旗| 禄丰县| 滨海县| 棋牌| 喜德县| 江北区| 天柱县| 灵石县| 防城港市| 文化| 孝感市| 垫江县| 嫩江县| 盈江县|