2017-03-22 61 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; 
    }