- 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.
- Vue.js 2 and Bootstrap 4 Web Development
- Selenium Design Patterns and Best Practices
- Java開發(fā)入行真功夫
- Mastering PHP Design Patterns
- Podman實(shí)戰(zhàn)
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- BIM概論及Revit精講
- Java EE核心技術(shù)與應(yīng)用
- FPGA Verilog開發(fā)實(shí)戰(zhàn)指南:基于Intel Cyclone IV(進(jìn)階篇)
- 深入分布式緩存:從原理到實(shí)踐
- C/C++數(shù)據(jù)結(jié)構(gòu)與算法速學(xué)速用大辭典
- ArcGIS for Desktop Cookbook
- uni-app跨平臺(tái)開發(fā)與應(yīng)用從入門到實(shí)踐
- SAS編程演義
- 計(jì)算機(jī)輔助設(shè)計(jì)與繪圖技術(shù)(AutoCAD 2014教程)(第三版)