Search code examples
yii

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?


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'
    
        ],
    
        ...
    
     ],
    
    ];