【问题标题】:How to change YAML value from Controller in Symfony如何在 Symfony 中从 Controller 更改 YAML 值
【发布时间】:2017-08-14 17:11:00
【问题描述】:

我想更改我的 config.yml 的值 我需要从我的 DefaultController.php 中更改它,但我不知道这是否可行(以及是否可行)。

YAML 文件

 google:
    enabled: true          # If Google Authenticator should be enabled, default false
    server_name: Zioo      # Server name used in QR code
    issuer: Zioo           # Issuer name used in QR code
    template: ZPAdminBundle:Authentication:form.html.twig   # Template used to render the authentication form

当用户不想使用此选项时,我需要将默认控制器的“启用”更改为 false。

【问题讨论】:

  • 配置相关的捆绑信息也很好。您实际上无法在运行时修改 YAML 配置,但在大多数情况下,捆绑包将填充您可以从容器访问的值对象。尽管这可能仍然不起作用,因为捆绑包可能在您的控制器之前完成了它的职责。因此,请同时提供捆绑信息,然后您可能会得到一些答案。
  • 感谢您的回复!文档可以在这里找到:github.com/scheb/two-factor-bundle/blob/master/Resources/doc/… 但是我找不到任何关于启用/禁用“启用”选项的信息

标签: symfony authentication yaml two-step-verification


【解决方案1】:

解决了!

在用户中,我为 GoogleAuth 设置了 IsActivated 值

 /**
 * @return mixed
 */
public function getGoogleAuthenticatorIsActivated()
{
    return $this->googleAuthenticatorIsActivated;
}

/**
 * @param mixed $googleAuthenticatorIsActivated
 */
public function setGoogleAuthenticatorIsActivated($googleAuthenticatorIsActivated)
{
    $this->googleAuthenticatorIsActivated = $googleAuthenticatorIsActivated;
}

然后我检查了它是否被激活。如果不是,则返回 NULL。如果“getGoogleAuthenticatorSecret”返回 NULL,捆绑包会自动禁用 google 身份验证

    public function getGoogleAuthenticatorSecret()
    {

    if($this->getGoogleAuthenticatorIsActivated() == true){
        return $this->googleAuthenticatorSecret;
    }

    return NULL;
    }

【讨论】:

    猜你喜欢
    • 2011-03-15
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多