TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Session usage
  • I want to use Kohana Session in several Classes. Is there a Problem to instantiate a Singelton in multiple Classes with Session::instance('type') or should I use a wrapper Class which holds one Session Singelton instance.

    So what is better? One Wrapper Class with one Session instance or $session=Session::instance('type') all the way wherever Session is needed?

  • Session::instance is already a singleton

  • No.

    Session::instance is a method to create several instances in Session: /** * @var array session instances */ public static $instances = array();

    Thats fine to create what ever you want, but horrible in usage. So I think I'm going to use a Wrapper Class that holds only one instance.

  • Well, it would be cleaner and more testable to inject a Session instance to any class that needs to access it.

    However, as loonies says, Session::instance is already a singleton - the only reason that instances is an array is because it will produce one singleton for each type. Eg Session::instance ('cookie') always has the same result, but Session::instance ('native') will give a singleton of the native session driver.

    So there's no benefit to a wrapper class - either call Session::instance anywhere, or call it once in controller or wherever and inject the result anywhere it's needed.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion