我已经创建了一个JSON文件,我将使用它作为应用程序全局配置的数据源。
摘录自json文件
//Have not put the complete json file. No error in the file
{
"loginType":[
{
"name":"Facebook",
"url":"#",
"method":"",
"label":"Continue with Facebook",
"type":"social",
"class":"",
"icon":"",
"callBack_url" : "fbLoginUrl",
"providerButton":"<div class='fb-login-button' data-max-rows='1'
data-size='large' data-button-type='continue_with' data-use-
continue-as='true'></div>"
},
{
"name":"Twitter",
"url":"#",
"method":"logInWithTwitter()",
"label":"Continue with Twitter",
"type":"social",
"class":"",
"icon":"",
"callBack_url" : "twitterLoginUrl",
"providerButton" :""
}
]
}
json文件中的callBack_url密钥有一个名称类似的变量,它的值是一个url,例如$twitterLoginUrl = "https://some.site.com/twitter_login?param1“
$jsonData_signIn =json_decode
(file_get_contents(/path/to/oauth2_provider.json));
$oauth2Provider = jsonData_signIn->loginType;
foreach($oauth2Provider as $type){
if($type->type == 'local' ){
echo "<a href=\"{$type->callBack_url}\">{$type->label}</a>";
}
}
对于上面的,作为链接的输出,我得到了例如<a href="$fbLoginURL">Continue with facebook</a>
echo "<a href=\"{${$type->callBack_url}}\">{$type->label}</a>";
我没有存储完整的URI的原因是我将动态生成一些参数。
https://stackoverflow.com/questions/50688143
复制相似问题