如何在 Symfony 中包含多个 php 库? [英] How to include multiple php libraries in Symfony?

查看:28
本文介绍了如何在 Symfony 中包含多个 php 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我的 apps/myprogram/lib 文件夹中有一些 php 文件.例如应用程序/myprogram/lib/myLibA.class.php

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

当我在我的模块/动作/脚本中运行并尝试使用 myLibA 中的函数时,我不能.因为 symfony 抱怨 myLibA 类没有定义.

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.

我需要在 symfony 框架中的任何地方指定 myLibA.class.php 是必需的库吗?

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

推荐答案

Symfony 的自动加载器默认在顶级 /lib 目录中查找您的类.将在该目录或以下目录中的任何文件(供应商"除外)中搜索类.Symfony 搜索任何带有类声明的 .php 文件并将它们添加到自动加载系统中.

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.

此外,您可以在应用程序的 autoload.yml 文件中添加搜索路径.例如,对于我的一个应用程序,我将第三方 Flickr 库放在 /vendor/phpFlickr 和我的 /apps/frontend/config/autoload.yml 文件看起来像:

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

这允许自动加载 .../vendor/phpFlickr 下面的所有类.

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

这篇关于如何在 Symfony 中包含多个 php 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆