Home  >  Article  >  Backend Development  >  Can yii2 controller events be configured in the configuration file?

Can yii2 controller events be configured in the configuration file?

WBOY
WBOYOriginal
2016-12-01 01:27:481186browse

In Yii2, if you want to execute certain logic before the specific operation method, what should you do?

The current approach is to extract a basic controller and write it in the beforeAction inside.

I would like to ask if it can be configured through the configuration file and how to configure it.

Thank you

Reply content:

In Yii2, if you want to execute certain logic before the specific operation method, what should you do?

The current approach is to extract a basic controller and write it in the beforeAction inside.

I would like to ask if it can be configured through the configuration file and how to configure it.

Thank you

Resolved

$params = array_merge(
        require(__DIR__ . '/../../common/config/params.php'), require(__DIR__ . '/../../common/config/params-local.php'), require(__DIR__ . '/params.php'), require(__DIR__ . '/params-local.php')
);
return [
    'id'                  => 'back-frontend',
    ...
    'components'          => [
        ...
    ],
    'on beforeAction'     => [
        \frontend\behaviors\CheckPermission::className(), 'kunxTest',
    ],
    ...
];

Content comes from: link description

Statement:
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