- 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.
- Practical Data Analysis Cookbook
- Mastering Concurrency Programming with Java 8
- Mastering Entity Framework Core 2.0
- Power Up Your PowToon Studio Project
- Practical UX Design
- Learning RxJava
- 認識編程:以Python語言講透編程的本質
- INSTANT MinGW Starter
- Mastering Predictive Analytics with Python
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- Learning OpenStack Networking(Neutron)(Second Edition)
- 編程與類型系統
- Xcode 6 Essentials
- Oracle實用教程