- Drupal 8 Module Development
- Daniel Sipos
- 184字
- 2021-07-02 15:45:18
Redirecting from a Controller
In this chapter, we wrote a Controller that returns a render array. We know from the preceding chapter that this is picked up by the theme system and turned into a response. In Chapter 4, Theming, we will go into a bit more detail and see how this process is done. However, this render pipeline can also be bypassed if the Controller returns a response directly. Let's consider the following example:
return new Response('my text');
This will bypass much of Drupal, in fact, and return a blank white page with only the "my text" string on it. The Response class we're using is from the Symfony HTTP Foundation component.
However, we also have a handy RedirectResponse class that we can use, and it will redirect the browser to another page:
return new RedirectResponse('node/1');
The first parameter is the URL where we want to redirect. Typically, this should be an absolute URL; however, browsers nowadays are smart enough to handle a relative path also, as in the preceding example. So, in this case, the Controller will redirect us to that path.
- 現代C++編程:從入門到實踐
- R語言數據分析從入門到精通
- Oracle 11g從入門到精通(第2版) (軟件開發視頻大講堂)
- 算法零基礎一本通(Python版)
- Web交互界面設計與制作(微課版)
- Django:Web Development with Python
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第2版)
- Bootstrap Essentials
- The Data Visualization Workshop
- SharePoint Development with the SharePoint Framework
- Protocol-Oriented Programming with Swift
- JavaScript應用開發實踐指南
- Clojure for Machine Learning
- QPanda量子計算編程
- QlikView Unlocked