Mautic Community Forums

Configuring a variable in addon bundle.

Hello Mautic team!



I am a good at PHP but junior at symfony and mautic. I have read articles and managed to create a new addOn bundle and set it up to work perfectly.

In my folder I have MyBundleName/Config/config.php where I have written necessary array. Now I want to configure a constant variable to my bundle for ex: SOME_TOKEN = “hardcoded” and access this variable in my bundle’s controller method. I tried to add a new key to config array like this:

‘parameters’ => array(

‘some_token’ => ‘hardcoded’

),



and when I try to access it from controller like this: $this->container->getParameter(‘some_token’) it generates a error log. This may be due to my poor info about symfony framework but as far as I read you have modified the framework.

Thank you in advance!

Hi Chad

Information you provided was very helpful!

Thank you very much for your support!

Hi Kleand

To access those parameters you have to use a special factory get function:

https://github.com/mautic/mautic/blob/staging/app/bundles/CoreBundle/Factory/MauticFactory.php#L725-L754

You’ll want to use the ‘incudeAddonss’ flag to true so that it gets it properly. And you’ll need to use the factory service to call up to the factory.

There’s detailed info on how to use factory here:
http://mautic.github.io/developer-documentation/#factory-service

Hello Mautic team!

I am a good at PHP but junior at symfony and mautic. I have read articles and managed to create a new addOn bundle and set it up to work perfectly.
In my folder I have MyBundleName/Config/config.php where I have written necessary array. Now I want to configure a constant variable to my bundle for ex: SOME_TOKEN = “hardcoded” and access this variable in my bundle’s controller method. I tried to add a new key to config array like this:
‘parameters’ => array(
‘some_token’ => ‘hardcoded’
),

and when I try to access it from controller like this: $this->container->getParameter(‘some_token’) it generates a error log. This may be due to my poor info about symfony framework but as far as I read you have modified the framework.
Thank you in advance!