How to define Global Variables

6 years ago

jefflee
Member | 1
+
0
-

Hello,

How can I define global variables for all presenters and for my own classes?
I need to define many parameters to config my application.

Thanks,

Jeff

6 years ago

mkoubik
Generous Backer | 734
+
0
-

In config.neon:

parameters:
    foo: 'Hello world!'

In presenter you can access it by $this->context->parameters['foo'], or even better by registering presenter as a service (see below).
In your own services, you can pass parameters to constructor:

class MyService
{
    private $foo;

    public function __construct($foo)
    {
        $this->foo = $foo;
    }
}

config.neon:

services:
    - MyService(%foo%)