如何将 main.php 中的变量访问到另一个 php 文件中
how to access variables in main.php into another php file
我对 php 使用 yii2 框架的 Web 开发还很陌生。我正在开发一个 Web 应用程序,我的 return of main.php 文件(config 文件夹)中几乎没有变量。
return [
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
//some fields
],
'google' => [
'class' => 'yii\authclient\clients\GoogleOAuth',
'clientId' => 'somerandomnumber.apps.googleusercontent.com',
'clientSecret' => '6f7g8h9i10j',
],
],
],
]
我必须在模型文件夹的 php 文件中使用 google's clientId
。
<a href="https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2FCURRENT-DOMAIN%2Fgoogle%2Dlogin&response_type=permission&scope=email+profile+openid&client_id=GET THE CLIENT ID HERE">
<div class="gplus_seperator">
<div class="social_logo">
<span class="icon-font">p</span>
</div>
<div class="social_text">Sign in with Google+</div>
</div>
</a>
谁能帮帮我。 TIA
您可以使用以下方式访问组件:
Yii::$app->components['authClientCollection']['clients']['google']['clientId'];
我对 php 使用 yii2 框架的 Web 开发还很陌生。我正在开发一个 Web 应用程序,我的 return of main.php 文件(config 文件夹)中几乎没有变量。
return [
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
//some fields
],
'google' => [
'class' => 'yii\authclient\clients\GoogleOAuth',
'clientId' => 'somerandomnumber.apps.googleusercontent.com',
'clientSecret' => '6f7g8h9i10j',
],
],
],
]
我必须在模型文件夹的 php 文件中使用 google's clientId
。
<a href="https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2FCURRENT-DOMAIN%2Fgoogle%2Dlogin&response_type=permission&scope=email+profile+openid&client_id=GET THE CLIENT ID HERE">
<div class="gplus_seperator">
<div class="social_logo">
<span class="icon-font">p</span>
</div>
<div class="social_text">Sign in with Google+</div>
</div>
</a>
谁能帮帮我。 TIA
您可以使用以下方式访问组件:
Yii::$app->components['authClientCollection']['clients']['google']['clientId'];