[英]composer autoload.php failed to open stream: no such file or directory
[英]Failed to open stream using composer autoload
我只是通過運行這個命令的composer require phpmailer/phpmailer
包含在probject文件夾中的phpmailer: composer require phpmailer/phpmailer
里面的文件夾: application/assets/
我在index.php文件中包含以下命令:
include 'application/assets/vendor/autoload.php';
但不幸的是我得到了這個錯誤:
警告:include(application / assets / vendor / autoload.php):無法打開流:第74行/var/www/html/projects/MyApp/index.php中沒有此類文件或目錄
這是我的應用程序的樹視圖:
>MyApp
>application
>assets
>vendor
>autoload.php
>system
>index.php
在vendor
文件夾里面我有composer
和phpmailer
文件夾,如果我手動包含phpmailer類我沒有收到任何錯誤,這只有在我包含作曲家自動加載時才會發生。
這是autoload.php
的內容:
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit13c998efcdd189d437d19150f7ef3bc9::getLoader();
我不確定子文件夾/application/assets/
的安裝是否必須,但我建議使用標准文件夾布局:
Step1在index.php
旁邊創建一個composer.json
\- MyApp
\- application
\- system
\- index.php
\- composer.json
然后將phpmailer/phpmailer
添加到此composer.json
文件的require部分:
{
"require": {
"phpmailer/phpmailer": "^5.2"
}
}
然后運行composer update
。
(或者,您也可以在MyApp
文件夾中運行composer require phpmailer/phpmailer
。它會自動為您生成composer.json
文件)
依賴項將被提取到文件夾: vendors
,這意味着您的文件夾結構現在看起來像這樣:
\ MyApp
\ application
\ system
\ vendor <-- new folder with composer autoloaders and dependencies
\ index.php
\ composer.json
Step2最后,將Composer Autoloader添加到index.php
require __DIR__ . '/vendor/autoload.php';
就是這樣......開始使用你的依賴: $mail = new PHPMailer;
引用:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.