问题
I have a symfony 1.4 application with some classes for connecting to a SOAP web service stored in apps/appname/lib. When I try to access the sfConfig class to get some variables I have set in app.yml, an error is thrown since the application doesn't recognize sfConfig::get('app_myvar') as a method being called on a class.
How do I make the sfConfig class available to the classes in my apps/appname/lib directory?
This is the error I'm getting
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /Users/my/Sites/mySite/apps/frontend/lib/mySOAP.class.php on line 9
And here is the top of my class:
class mySOAP extends SoapClient {
protected $client = null;
protected $soapUrl = sfConfig::get('app_my_url');
protected $options = array(
'trace' => 1,
'exceptions' => 1,
'soap_version' => SOAP_1_2,
//'encoding' => 'ISO-8859-1',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
Line 9 is
protected $soapUrl = sfConfig::get('app_my_url');
回答1:
The sfConfig class is loaded automatically when the Symfony stack is 'booted'. So either your running through the index.php (or any other frontend controller) or the CLI, you should have access to the sfConfig.
So my best guess is that you either haven't successfully set up the Symfony stack (though this should throw other errors in an earlier stage), or your trying to access the app.yml from a script outside Symfony? In the latter case, you could either boot up Symfony or include the sfYaml parser and parse the app.yml yourself.
来源:https://stackoverflow.com/questions/7679974/access-sfconfig-class-in-apps-appname-lib