- 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.
- 摩登創客:與智能手機和平板電腦共舞
- Java Web及其框架技術
- INSTANT Sencha Touch
- 機器人Python青少年編程開發實例
- Implementing Cisco Networking Solutions
- 編寫高質量代碼:改善C程序代碼的125個建議
- Full-Stack Vue.js 2 and Laravel 5
- Monitoring Elasticsearch
- Expert Android Programming
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- Creating Stunning Dashboards with QlikView
- Domain-Driven Design in PHP
- 物聯網系統架構設計與邊緣計算(原書第2版)
- Drupal 8 Development Cookbook(Second Edition)
- C# 7.0本質論