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

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.

主站蜘蛛池模板: 庆云县| 东乡县| 嘉义县| 茶陵县| 镇原县| 布拖县| 甘孜县| 菏泽市| 城固县| 营口市| 镇巴县| 赤城县| 呼和浩特市| 太保市| 克什克腾旗| 巴马| 米脂县| 蓬溪县| 通城县| 临沂市| 富裕县| 香格里拉县| 大渡口区| 梁山县| 科技| 五指山市| 台江县| 苗栗市| 林州市| 河间市| 西华县| 牟定县| 达日县| 芮城县| 广水市| 合作市| 保靖县| 福海县| 秦皇岛市| 濮阳县| 鄯善县|