Can't get the php-sdk to work from my Yii application

Ernesto

Member
Hi, I tested the mailwizz-php-sdk examples and they worked great.
But now I'm trying to test calling the SDK from within a controller of my Yii app, but can't make the Autoloader work.

I get this error: include(MailWizzApi_Config.php): failed to open stream: No such file or directory
Because my own App's autoloader is trying to find the class.

Note: the path of the require_once() is correct, the file can be found, but the autoloader doesn't work for some reason. The API keys are also correct.

PHP:
require_once( __DIR__ .'/../../mailwizz-php-sdk/MailWizzApi/Autoloader.php' );

class TestController extends Controller
{
    protected function setupMailWizz()
    {
        MailWizzApi_Autoloader::register();
        
        $config = new MailWizzApi_Config(array(
            'apiUrl'        => 'http://localdomain.loc/mailwizz/api/index.php',
            'publicKey'     => '...',
            'privateKey'    => '...',
            
            // components
            'components' => array(
                'cache' => array(
                    'class'     => 'MailWizzApi_Cache_File',
                    'filesPath' => __DIR__ .'/../../mailwizz-php-sdk/MailWizzApi/Cache/data/cache'
                )
            ),
        ));
        // now inject the configuration and we are ready to make api calls
        MailWizzApi_Base::setConfig($config);
    }
    
    public function actionLists()
    {
        $this->setupMailWizz();
        $endpoint = new MailWizzApi_Endpoint_Lists();
        $response = $endpoint->getLists($pageNumber = 1, $perPage = 10);

        // DISPLAY RESPONSE
        echo '<pre>';
        print_r($response->body);
        echo '</pre>';
    }
 

twisted1919

Administrator
Staff member
@Ernesto - not sure if you saw this in the setup.php file from the examples, but we have this comment:
PHP:
// register the autoloader.
MailWizzApi_Autoloader::register();

// if using a framework that already uses an autoloading mechanism, like Yii for example,
// you can register the autoloader like:
// Yii::registerAutoloader(array('MailWizzApi_Autoloader', 'autoloader'), true);
So you could try
PHP:
Yii::registerAutoloader(array('MailWizzApi_Autoloader', 'autoloader'), true);


If that does not work either, you can try to autoload like:
PHP:
spl_autoload_register(array('MailWizzApi_Autoloader', 'autoloader'), true, true);

// and regular code..
$config = new MailWizzApi_Config(array( ...
 
Top