Claudiu
Claudiu

Reputation: 47

How to extend CHttpSession class in yii1

First I want to say that i am really new in programming yii1.I have to catch the event when session is destroyed or closed in yii1 and redirect to index when the event is triggered.

I've tried to extend CHttpSession class and extend the method sessionDestroy(), but i miss something because my solution is not working.

My class that extends CHttpSession that is located in components folder:

class SessionDestroy extends CHttpSession {

  public function destroySession($id) {
    Yii::log('destroy', 'info');
    $result = parent::destroySession($id);

    return $result;
  }

}

Then in my controller i have:

      $session = new CHttpSession;
      $session->open();
      ...
      $session->destroy();

I expect to see in log the destroy info message but nothing happens.

Upvotes: 0

Views: 163

Answers (1)

Sam Dark
Sam Dark

Reputation: 5291

Extending part is right. Then you need to configure session component to use your new class:

'components' => [
    // ...
    'session' => [
        'class' => 'SessionDestroy',
    ],
]

See https://www.yiiframework.com/doc/guide/1.1/en/basics.application#application-components

Upvotes: 1

Related Questions