- Drupal 8 Module Development
- Daniel Sipos
- 223字
- 2021-07-02 15:45:17
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.
- R語(yǔ)言數(shù)據(jù)分析從入門到精通
- Java面向?qū)ο笏枷肱c程序設(shè)計(jì)
- Vue.js前端開(kāi)發(fā)基礎(chǔ)與項(xiàng)目實(shí)戰(zhàn)
- 劍指JVM:虛擬機(jī)實(shí)踐與性能調(diào)優(yōu)
- Visual C++數(shù)字圖像模式識(shí)別技術(shù)詳解
- Mastering Articulate Storyline
- Learning SQLite for iOS
- C語(yǔ)言程序設(shè)計(jì)實(shí)踐教程
- Kinect for Windows SDK Programming Guide
- Android底層接口與驅(qū)動(dòng)開(kāi)發(fā)技術(shù)詳解
- 程序是怎樣跑起來(lái)的(第3版)
- SQL基礎(chǔ)教程(第2版)
- 新一代SDN:VMware NSX 網(wǎng)絡(luò)原理與實(shí)踐
- Mastering Apache Storm
- C指針原理揭秘:基于底層實(shí)現(xiàn)機(jī)制