How to include multiple php libraries in Symfony?

孤者浪人 提交于 2019-12-22 11:37:11

问题


so, I have some php files in my apps/myprogram/lib folder. e.g. apps/myprogram/lib/myLibA.class.php

When I run in my modules/actions/ scripts, and try to use the functions in myLibA, I cannot. because symfony complains that the myLibA class is not defined.

do I need to specify anywhere in the symfony framework that myLibA.class.php is a required library?


回答1:


Symfony's autoloader looks by default for your classes in the top-level <project>/lib directory. Any file in that directory or below (with the exception of "vendor") will be searched for classes. Symfony searches for any .php file with class declarations and adds them to the autoload system.

Additionally, you can add search paths in your application's autoload.yml file. For example, for one of my applications I've put a third-party Flickr library in <project>/vendor/phpFlickr, and my <project>/apps/frontend/config/autoload.yml file looks like:

autoload:
    vendor_php_flickr:
        path: %SF_LIB_DIR%/vendor/phpFlickr
        recursive: on

That allows all classes below .../vendor/phpFlickr to be autoloaded.




回答2:


this is an alternative way, you can define/add to your preExecute this:

public function preExecute()
{
  $this->getContext()->getConfiguration()->loadHelpers('Foo', 'Bar');
}

taken from (http://oldforum.symfony-project.org/index.php/m/92916/)



来源:https://stackoverflow.com/questions/5507440/how-to-include-multiple-php-libraries-in-symfony

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