Replies: 1 comment 5 replies
-
|
If you want to autowire an env var to a controller argument with no configuration you can use the |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to use secrets as explained on this page:
https://symfony.com/doc/current/configuration/secrets.html
I have defined my secrets and they show up properly using
php bin/console secrets:list --reveal. They seem to be working fine when referenced inside a .yaml file (my database password is being passed in correctly), but I can't figure out how to access the values within PHP -- inside a controller specifically.Based on this example:
I'm trying to simply do:
But I get an error
Attempted to call undefined function "env" from namespace "App\Controller".I see tons of examples in the documentation talking about using 'env()' ... but it is not clear if I need to include a specific class in my controller to access it. Does the env() function only work within "configuration" classes? If so, then how do I get the secret value inside a controller so I can actually do something with it.
I've also tried:
and
but those aren't working either.
I have confirmed that I have symfony/dotenv installed (v7.3.2). Doing
php bin/console debug:dotenvdoes not show any of the secrets configured usingphp bin/console secrets:setI'm running Symfony 7.3.6 and PHP 8.4.14. PHP has Sodium support installed/enabled.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions