- Drupal 8 Module Development
- Daniel Sipos
- 217字
- 2021-07-02 12:22:41
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.
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- JMeter 性能測試實戰(第2版)
- 三維圖形化C++趣味編程
- 從0到1:HTML+CSS快速上手
- Java程序設計與實踐教程(第2版)
- 名師講壇:Java微服務架構實戰(SpringBoot+SpringCloud+Docker+RabbitMQ)
- C++程序設計基礎教程
- PLC編程與調試技術(松下系列)
- Elasticsearch Server(Third Edition)
- Learning OpenCV 3 Computer Vision with Python(Second Edition)
- Python程序設計與算法基礎教程(第2版)(微課版)
- 小型編譯器設計實踐
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通
- C語言程序設計實訓教程與水平考試指導
- Java EE 7 with GlassFish 4 Application Server