在每个动作之前调用一个组件方法

Call a component method before every action

我有一个组件,想在每次操作前调用它。 那么我该如何调用它,我需要当前的动作名称

 $this->actionname()

谢谢

将其添加到 main.php 文件中

'as beforeRequest' => [
    'class' => 'path\to\your-components' \ api\components\mycomponent
],

这将在每个请求之前调用您的组件

获取当前动作名称

Yii::$app->request->resolve()[0]