为什么我的autoload.php作曲家不起作用?

Mat*_*alò 18 php dependencies composer-php respect-validation

我有一个项目,我使用Composer,我导入很多东西...我需要我的索引(项目的根)中的autoload.php和istead Slim,Mongo,Twig工作得非常好.但是,当我打电话给一类尊重/验证时,它不起作用; 如果我只是使用Respect/Validation,则错误是:

Class 'Respect\Validation\Validator' not found in (path of file when i need it).

如果我在这里也要求autoload.php错误是:

**Warning**: require_once(vendor/autoload.php): failed to open stream: No such file or directory in (path of file when i need it)

**Fatal error**: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in (path of file when i need it)

cir*_*van 22

尝试使用php composer dump-autoload.它可以解决这个问题.


Dav*_*ore 18

如果您file.php在特定目录中使用file(),如下所示:

/app/controller/validation
Run Code Online (Sandbox Code Playgroud)

并且您的供应商目录位于项目的基本路径中,您需要包含供应商目录的相对路径:

../../../vendor/autoload.php
Run Code Online (Sandbox Code Playgroud)


Abh*_*ari 8

我这样做了 我一如既往地检查文件和权限,但一切看起来都不错.然后我打开autoload.php看看......哦!我们有__DIR__.

我这样做

require '../../vendor.autoload.php';

变成

require __DIR__.'../../vendor.autoload.php';

在政治上不正确,但让我感到沮丧的浪费时间.

当然,有更好的选择,__DIR__比如使用BASE Path等.但这对我有用.

  • 2016年......我也搬到了蟒蛇.:P (2认同)