We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how to rewrite functions in Phalcon\Session\Adapter\Redis

hi all! i want to rewrite functions in Phalcon\Session\Adapter\Redis. so can i do it??? ex: rewrite: public function write(), public function read()... thanks so!



77.7k
Accepted
answer

Sure, create your own class:

class MyRedisAdapter extends \Phalcon\Session\Adapter\Redis
{
    public function write() {
        // ...
    }
    public function read() {
        // ...
    }
}

Then register this as your session adapter in services:

$di->setShared('session', function() {
    $session = new MyRedisAdapter();
    return $session;
});

Yes. Just create your class and extend Phalcon\Session\Adapter\Redis



4.3k

thank you! usefull

Sure, create your own class:

class MyRedisAdapter extends \Phalcon\Session\Adapter\Redis
{
  public function write() {
      // ...
  }
  public function read() {
      // ...
  }
}

Then register this as your session adapter in services:

$di->setShared('session', function() {
  $session = new MyRedisAdapter();
  return $session;
});


4.3k

sorry, can you tell me where is the class MyRedisAdapter place in project??? thanks

Sure, create your own class:

class MyRedisAdapter extends \Phalcon\Session\Adapter\Redis
{
  public function write() {
      // ...
  }
  public function read() {
      // ...
  }
}

Then register this as your session adapter in services:

$di->setShared('session', function() {
  $session = new MyRedisAdapter();
  return $session;
});

Depends on your your project layout, you have to register it with the class loader: https://docs.phalcon.io/en/latest/reference/loader.html



4.3k

my file structure as example of phalcon and what i should use???

Registering Directories ,Registering Classes, Registering Namespaces! thank you for help!

Depends on your your project layout, you have to register it with the class loader: https://docs.phalcon.io/en/latest/reference/loader.html