在Symfony 4中,我尝试从.env中传递参数 到控制器:
.env
中:###> First user creation variables ###
FIRST_USER_LOGIN=admintest
FIRST_USER_PASSWORD=azertyui
###< First user creation variables ###
services.yaml
中:parameters:
locale: 'en'
first.user:
login: '%env(FIRST_USER_LOGIN)%'
password: '%env(FIRST_USER_PASSWORD)%'
$utilisateur->setUsername($this->getParameter('first.user.login'))
->setPassword(
$encoder->encodePassword(
$utilisateur,
$this->getParameter('first.user.password')
)
)
->setRoles(['ROLE_ADMIN']);
The parameter "first.user.login" must be defined.
答案 0 :(得分:1)
解决了,我很傻,只需更改services.yaml
:
parameters:
locale: 'en'
first.user.login: '%env(FIRST_USER_LOGIN)%'
first.user.password: '%env(FIRST_USER_PASSWORD)%'