简体   繁体   English

在wordpress主题中使用composer并自动加载,“需要打开失败”

[英]using composer and autoload in wordpress theme, 'Failed opening required'

So I've installed createsend-php for my theme via composer (I'm trying to learn how too use it) but can't get to the next stage. 因此,我已经通过composer为主题安装了createsend-php(我正试图学习如何使用它),但无法进入下一阶段。

I can see the API here - /wp-content/themes/wonkhe2-theme/vendor/campaign-monitor/createsend-php/ 我在这里可以看到API- /wp-content/themes/wonkhe2-theme/vendor/campaign-monitor/createsend-php/

composer file seems right to me - 作曲家文件似乎对我来说正确-

  "require": {
    "php": ">=5.4.0",
    "composer/installers": "~1.0",
    "campaignmonitor/createsend-php": ">=6.0"
  }

in /wp-content/themes/wonkhe2-theme/templates/content-signup-cm.php I've added require_once 'csrest_campaigns.php' 在/wp-content/themes/wonkhe2-theme/templates/content-signup-cm.php中,我添加了require_once 'csrest_campaigns.php'

And that returns 那又回来了

Fatal error: require_once(): Failed opening required 'csrest_campaigns.php' (include_path='.:/Applications/MAMP/bin/php/php7.2.7/lib/php') in /wp-content/themes/wonkhe2-theme/templates/content-signup-cm.php on line 5

Should the require_once path be different? require_once路径应该不同吗? I thought autoloader would set the paths and namespaces. 我以为自动加载器会设置路径和名称空间。

Using composer is new to me so apologies if I'm misunderstanding but any help appreciated. 使用composer对我来说是新手,所以如果我误会了我,我对此表示歉意,但对您的帮助不胜感激。

you should not require individual classes insalled by composer. 您不应要求作曲家单独授课。 instead, right at the start of your code: 相反,就在代码开头:

require_once 'vendor/autoload.php';

then you can just start using objects; 然后就可以开始使用对象了;

use Some\Class\Or\Other;

$object = new Other();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM