good practice replacing Nette\Environment ?

Notice: This thread is very old.
alnux
Member | 106
+
0
-

hi there, i was trying to find a way to replace Nette\Environment class on my app and get neon vars. but the just way that i find is to use the global way calling $container; from the index.php.

$foo = "hi there";
class someClass
{
	global $foo;
	echo $foo;
}

I did this becouse this have the system container. thats the way i ask this.

thanks for your suggestion.

PD: by the way $container have a compromising information

Last edited by alnux (2014-12-05 16:22)

Filip Procházka
Moderator | 4668
+
+3
-

How to get parameters from config in presenter or service, it's in czech but the code example should be clear.

The global and Environment is evil.

Last edited by Filip Procházka (2014-12-05 20:49)

alnux
Member | 106
+
0
-

thanks filip for your comment. But the question is how get the system container on class that does not is presenter by example. i have the conf.neon

parameters:
    # this is used for app verification, actual on: tables users_roles, permission. This does not influence on users pass
    appkey: 'Change this key with your own example: qaQadaWeR12'

    # To block the change of the super user please set it to 'false' and to edit to 'true'
    changesupacc: true

    # this word is used for: user, principal permission and principal role, set this at begining
    superaccess: 'superadministrator'

    # Database parameters
    database:
        driver: mysql
        host: localhost
        username: root
        password:
        dbname: herbanette

    # Country params and language white list to kdyby/translation whitelist and httpRequest, all in isoCode
    location:
        countrydefault: BO
        languagedefault: es
        langlist: [en, es, cs]

and i was using the \Nette\Environment to get the params outside a presenter becouse on presenter is just “$this->context->getParameters()” (it will be deprecated too??) and i dont know how to get the system container to get the params on classes that are not extended from presenter.

The same things with services of system container

$session = \Nette\Environment::getService('session');

i will really thanks if you help me with it
regards

Filip Procházka
Moderator | 4668
+
0
-

You shouldn't try to get the container, but rather have the parameters injected to classes where you need them. Forget the is a container :)

alnux
Member | 106
+
0
-

one ask more,

the next will be deprecated too????

$this->context->getParameters()
Filip Procházka
Moderator | 4668
+
0
-

$this->context will definitely get eventually deprecated :)