Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would imagine that you could first register your session model in the service manager in the Module.php of whatever module you desire so that it is globally available, and use this service any time you need to access the session.</p> <pre><code>public function getServiceConfig() { return array( 'factories' =&gt; array( 'AppSession' =&gt; function($sm) { $session = new \Path\To\Session(); $session-&gt;doSomething(); return $session; } ) ); } </code></pre> <p>When you register your various models throughout your application in the service manager, inject your session service then.</p> <pre><code>public function getServiceConfig() { return array( 'factories' =&gt; array( 'Application\Model\SomeThing' =&gt; function($sm) { $c = new SomeThing(); // You will have to create the set and get functions. $c-&gt;setDbAdapterService($sm-&gt;get('Zend\Db\Adapter\Adapter')); $c-&gt;setSessionService($sm-&gt;get('AppSession')); return $c; } ) ); } </code></pre> <p>And on your controller too, it might make more sense to inject the session from the start so that the session is ready and waiting for you. </p> <p>In your module.config.php...</p> <pre><code>return array( 'controllers' =&gt; array( 'factories' =&gt; array( 'Application\Controller\Something' =&gt; function ($sm) { $locator = $sm-&gt;getServiceLocator(); $c = new Application\Controller\SomethingController(); $c-&gt;setSessionService($locator-&gt;get('AppSession')); return $c; }, ), ), 'router' =&gt; array( 'routes' =&gt; array( 'myroute' =&gt; array( 'type' =&gt; 'Zend\Mvc\Router\Http\Segment', 'options' =&gt; array( 'route' =&gt; '[/:action]', 'defaults' =&gt; array( 'controller' =&gt; 'Application\Controller\Something', 'action' =&gt; 'index', ), ), ), ), ), ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload