Tuesday, January 18, 2022

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

Issue

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.

I can see the API here - /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'

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? 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.


Solution

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();


Answered By - delboy1978uk

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.