Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to disable a particular config component on specific action in YII2?

i have a user component in my web config file which is working fine.

$config = [

    'components' => [

        'user' => [

            'class' => 'common\components\User'

        ],

        ...

    ],

];

except on a page where I want to use a different user file. Is it possible to disable the particular component in Yii for a particular action?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are several ways foe example You could declare two different components

$config = [

'components' => [

    'user' => [

        'class' => 'common\components\User'

    ],

   'user1' => [

        'class' => 'common\components\MyAlternativeUser'

    ],

    ...

 ],

];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading