2017-03-22 64 views
0

我想更改我的config.yml的值 我需要将其从DefaultController.php中更改,但我不知道这是否可能(以及是否有可能如何去做吧)。如何在Symfony中更改控制器中的YAML值

的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 

我需要从defaultcontroller更改“已启用”为false时,用户不希望使用此选项。

+0

关于配置涉及的绑定的信息也不错。您不能在运行时实际修改YAML配置,但在大多数情况下,该捆绑包将填充可从容器访问的值对象。虽然这可能仍然不起作用,因为捆绑可能在你的控制器之前完成了它的职责。所以请提供捆绑信息,那么你可能会得到一些答案。 –

+0

感谢您的回应! 该文档可以在这里找到:https://github.com/scheb/two-factor-bundle/blob/master/Resources/doc/configuration.md 但是我找不到任何有关启用/禁用“启用”选项 –

回答

1

有一个修复!

在用户我做了IsActivated值的GoogleAuth

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

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

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

public function getGoogleAuthenticatorSecret() 
    { 

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

    return NULL; 
    }