- 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.
- Spring Cloud Alibaba核心技術與實戰案例
- Developing Mobile Web ArcGIS Applications
- Python從入門到精通(精粹版)
- 微服務設計原理與架構
- Interactive Applications Using Matplotlib
- bbPress Complete
- Learning OpenStack Networking(Neutron)
- Mastering Business Intelligence with MicroStrategy
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- Node.js區塊鏈開發
- JavaScript從入門到精通(視頻實戰版)
- Clojure High Performance Programming(Second Edition)
- Get Your Hands Dirty on Clean Architecture
- INSTANT PLC Programming with RSLogix 5000
- 大話程序員:從入門到優秀全攻略