yii2 绑定框架事件

WBOY
Release: 2016-06-06 20:07:24
Original
955 people have browsed it

我想要添加自定义代码处理yii2框架的Application::EVENT_BEFORE_REQUEST时触发的事件,但是不知道这个事件的on方法应该写在什么位置,即

<code>\Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function ($event) {
    // ...
});</code>
Copy after login
Copy after login

的位置,请各位大侠指教,谢谢

回复内容:

我想要添加自定义代码处理yii2框架的Application::EVENT_BEFORE_REQUEST时触发的事件,但是不知道这个事件的on方法应该写在什么位置,即

<code>\Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function ($event) {
    // ...
});</code>
Copy after login
Copy after login

的位置,请各位大侠指教,谢谢

Application::EVENT_BEFORE_REQUEST
属于应用级,写在入口或配置文件上config/main.php
使用
'as beforeRequest' => [
'class' => '',
],

可以写在入口文件

突然发现点击,别人的答案有帮助,都需要声望达到15,好郁闷,只好用文字打了,支持 @liubadao

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!