Access sfConfig class in apps/appname/lib

流过昼夜 提交于 2019-12-11 18:10:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!