在控制器动作之前执行代码 [英] Execute code before controller's action

查看:26
本文介绍了在控制器动作之前执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中的所有操作之前执行代码(以计算一个重要的全局变量).如何在我的控制器中设置预操作功能?

I would like execute code before all actions in my project (to calculate an important global variable). How to set a pre-action function in my controllers ?

推荐答案

Symfony2 中没有 pre-action 方法.为此,您必须使用事件侦听器.

There's no pre-action method in Symfony2. You have to use event listeners for that purpose.

这篇关于在控制器动作之前执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆