首页 > 解决方案 > 在 wordpress 主题中使用作曲家和自动加载,“需要打开失败”

问题描述

所以我已经通过 composer 为我的主题安装了 createend-php (我正在尝试学习如何使用它)但无法进入下一阶段。

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

作曲家文件对我来说似乎是正确的-

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

在 /wp-content/themes/wonkhe2-theme/templates/content-signup-cm.php 我添加了 require_once 'csrest_campaigns.php'

这又回来了

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

require_once 路径应该不同吗?我认为自动加载器会设置路径和命名空间。

使用作曲家对我来说是新的,如果我有误解,我们深表歉意,但感谢任何帮助。

标签: phpwordpresscomposer-phpthemes

解决方案


您不应该要求作曲家安装单独的课程。相反,就在代码的开头:

require_once 'vendor/autoload.php';

然后你就可以开始使用对象了;

use Some\Class\Or\Other;

$object = new Other();

推荐阅读