官术网_书友最值得收藏!

Event Dispatcher and redirects

A common thing you'll have to do as a module developer is to intercept a given request and redirect it to another page, and more often than not, this will have to be dynamic, depending on the current user or other contextual info. Drupal 7 developers know very well that this has always been an easy task. Simply implement hook_init(), which gets called on each request and then use the famous drupal_goto() function. This, however, is no longer the case in Drupal 8. What we have to do now is subscribe to the kernel.request event (remember this from the preceding chapter?) and then change the response directly. However, before seeing an example of this, let's take a look at how we can perform a simpler redirect from within a Controller.

主站蜘蛛池模板: 辽阳市| 彭山县| 郴州市| 平武县| 栖霞市| 宜城市| 三明市| 岳阳县| 惠州市| 望江县| 巴林右旗| 正安县| 阳西县| 固镇县| 天柱县| 义乌市| 达尔| 清徐县| 襄城县| 镇赉县| 四子王旗| 陈巴尔虎旗| 通城县| 河津市| 定日县| 泊头市| 鄂托克前旗| 长子县| 藁城市| 吴旗县| 阳曲县| 正定县| 神池县| 双桥区| 和龙市| 沂南县| 固阳县| 祁东县| 梅州市| 庆城县| 梁河县|