欢迎我有一个文件 config.yml
d_facebook:
file: %kernel.root_dir%/../src/FacebookBundle/Facebook/FacebookInit.php
app_id: 296925470418713
secret: fb4d0a99bcf80e55f47077ffadcac921
cookie: true
permissions: [email, user_birthday, user_location, user_about_me, user_location]
然后我有这个类,它从文件 config.yml 中检索数据
<?php
namespace D\FacebookBundle\Facebook;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use D\FacebookBundle\Facebook\Facebook;
use D\FacebookBundle\Facebook\FacebookConfig;
class FacebookInit
{
public $hAPI;
public $userProfile;
public $user;
public $logoutUrl;
public $loginUrl;
public $config;
public function __construct()
{
$this->config = Yaml::parse('/facebookx/app/config/config.yml');
$this->hAPI = new Facebook(array(
'appId' => $this->config['d_facebook']['app_id'],
'secret' => $this->config['d_facebook']['secret']
));
$this->setUserProfile();
}
}
有什么更好的方法来做到这一点?如何从文件 config.yml 中获取变量?我问一个例子?