PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

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

 January 18, 2022     composer-php, php, themes, wordpress     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing