Jump to content

Recommended Posts

Posted

I am trying to connect with an external API, from marketing automation application Mautic on the same server, from a template in Processwire, with something like this:

require '/serverpath/vendor/autoload.php';

use Mautic\Auth\ApiAuth;
use Mautic\MauticApi;

$initAuth = new ApiAuth();

This works in an empty test page outside of Processwire. Trying to use it from a template within Processwire I get this error:

Quote

Fatal Error: Uncaught Error: Class 'ApiAuth' not found in site/templates/session.php:43

#0 wire/core/TemplateFile.php (318): require()
#1 wire/core/Wire.php (394): TemplateFile->___render()
#2 wire/core/WireHooks.php (823): Wire->_callMethod('___render', Array)
#3 wire/core/Wire.php (465): WireHooks->runHooks(Object(TemplateFile), 'render', Array)
#4 wire/modules/PageRender.module (536): Wire->__call('render', Array)
#5 wire/core/Wire.php (397): PageRender->___renderPage(Object(HookEvent))
#6 wire/core/WireHooks.php (823): Wire->_callMethod('___renderPage', Array)
#7 /wire/c (line 43 of site/templates/session.php)

How can I make sure the script looks for Mautic's ApiAuth in the correct place? 

Mautic's autoload.php is included in the page successfully; I have checked that.

 

Posted

Try adding a backslash prefix in front of the class namespace

use \Mautic\Auth\ApiAuth;
use \Mautic\MauticApi;

 

  • Like 1
Posted

@Rudy, thanks for the idea. I tried this, but it didn't make any difference, even after clearing caches etc.

Edit:

I figured it out. In the script I "called" the API with this:

$initAuth = new ApiAuth();

When I should have used:

$initAuth = new Mautic\Auth\ApiAuth();

To "declare" (?) the namespace. 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...