Can yii2 controller events be configured in the configuration file?

WBOY
Release: 2023-03-02 13:22:01
Original
1262 people have browsed it

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

<code>$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',
    ],
    ...
];</code>
Copy after login

Content comes from: link description

Related labels:
php
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!