Raekye
Raekye

Reputation: 5131

How to use Zend\Config (application wide variables)

Main question is self explanatory, but I'll give some side examples:


$container = new Zend\Session\Container('auth');
$container->offsetSet('user', $user);
... // instead of 
$container = new Zend\Zession\Container($config['auth']['containername']);
$container->offsetSet($config['auth']['user'], $user);

Upvotes: 1

Views: 2269

Answers (1)

Sam
Sam

Reputation: 16455

All configuration from each module.config.php or Module.php are put together into a big pot. You can easily access those via $this->getServiceLocator()->get('config')

When it comes down to constants, they should be placed inside the respective classes. Like

class UserStorage {
    const SESSIONCONTAINERNAME = 'blubbusersession';
}

That way you can call \My\User\Model\UserStorage::SESSIONCONTAINERNAME whenever you need this info

As far as your example is concerned thought, there should be almost no need to var-code your session-container-name because the information from your modules session-data should be made available via your modules Service-Classes. But if you still need it, see aboves example.

Furthermore i think it may be a good idea for you to check out how zf-commons\ZfcUser does things

Upvotes: 2

Related Questions