- Drupal 8 Module Development
- Daniel Sipos
- 219字
- 2021-07-02 12:22:42
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 \Symfony\Component\HttpFoundation\Response('my text');
This will bypass much of that processing 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 \Symfony\Component\HttpFoundation\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 as well. So, in this case, the Controller will redirect us to that path.
- 軟件安全技術
- 玩轉Scratch少兒趣味編程
- OpenCV實例精解
- Oracle Database In-Memory(架構與實踐)
- Mastering QGIS
- C/C++算法從菜鳥到達人
- Getting Started with PowerShell
- Learning Python Design Patterns(Second Edition)
- Xamarin.Forms Projects
- MATLAB 2020從入門到精通
- C語言程序設計
- Yii Project Blueprints
- The Professional ScrumMaster’s Handbook
- Android驅動開發權威指南
- Hands-On Full Stack Development with Spring Boot 2.0 and React