How to use Zend \ Config (wide application variables)

The main question is in itself, but I will give a few examples:

  • I'm having trouble finding databases, although it seems like I can configure with ServiceManager

  • I want to use constants for cookie names, so I can easily change them if there is a collision. Current, I'm calling $config = new \Zend\Config\Config(include $_SERVER['DOCUMENT_ROOT'] . '/../config.php'); every time I want to access my global config.php file. Many previous solutions were in Zend 1 (e.g. Zend_Registry). Is it correct? It seems a little cumbersome using it over and over.

  • Is there a way to use the module configuration file to set the variables / constants of the module?

  • If I don’t completely miss it, there is no .ini application in Zend 2

  • Saving public / private keys recaptcha

  • I also use my configuration file for session variables (same idea as $_SESSION[CONST_NAME] ), which makes it really awkward with the configuration file above. Is it better to hardcode session names? How:


 $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); 
+1
source share
1 answer

The entire configuration from each module.config.php or Module.php combined into a large bank. You can easily access them through $this->getServiceLocator()->get('config')

When it comes to constants, they should be placed inside the corresponding classes. how

 class UserStorage { const SESSIONCONTAINERNAME = 'blubbusersession'; } 

This way you can call \My\User\Model\UserStorage::SESSIONCONTAINERNAME whenever you need this information

As for your example, think that you will not need var-code to specify the name of your container session, because the information from your module session data should be available through your Service-Classes modules. But if you still need it, see the cancellation example.

Also, I think it might be a good idea for you to check how zf-commons\ZfcUser does things

+2
source

All Articles