[英]Avoid pathname Composer vendor/autoload
I used SSH to download composer and mailgun API Dependencies to my project. 我使用SSH将composer和mailgun API Dependencies下载到我的项目中。 Now For sending an email I had all the code in a file
mail.php
that has include('PATH to vendor/autoload.php')
and function send($to, $subject, $body)
. 现在,要发送电子邮件,我将所有代码包含在文件
mail.php
,该文件具有include('PATH to vendor/autoload.php')
和函数send($to, $subject, $body)
。
Now my problem is, when I try to include this file to send an email, include(PATH to vendor/autoload)
varies every time as I include this file in different scripts which have different paths. 现在我的问题是,当我尝试包含此文件以发送电子邮件时,每次将include这个文件包含在具有不同路径的不同脚本中时,
include(PATH to vendor/autoload)
都会有所不同。
All I am trying to acheive here is : have a file that has all of my code with a require(vendor/autoload.php)
. 我要在这里实现的只是:有一个文件,其中包含我的所有代码以及
require(vendor/autoload.php)
。 And everytime I need to send a email in a different script, I just want to include the file that has require(vendor/autoload.php)
without having the PATH everytime. 而且每次我需要使用其他脚本发送电子邮件时,我只想包含具有
require(vendor/autoload.php)
的文件,而不必每次都具有PATH。
Is that possible and how can I do it. 那有可能吗,我该怎么做。
Thanks in advance. 提前致谢。
You need to use __DIR__
magic constant to make path to vendor/autoload.php
absolute. 您需要使用
__DIR__
魔术常数来使指向vendor/autoload.php
路径成为绝对路径。 For example: 例如:
require __DIR__ . '/../vendor/autoload.php';
In this way it will always point to the same file regrades of place where you include/run this file. 这样,它将始终指向包含/运行此文件的位置的相同文件版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.