1

I have external library handling connection to mail delivery system. Its just php class. How do i include and use this class inside craft plugin controller?

library.php:

class mail_delivery{
    //code
}

plugin/controllers/controller.php:

namespace Craft;

class controller extends BaseController
{

    public function init()
    {
        require_once 'library.php';
    }

    public function method(){
        $object = $rest = new mail_delivery();
    }

I get PHP error:

( ! ) Fatal error: Class 'Craft\FmRestAPI' not found in C:\xampp\htdocs\mmimport\craft\plugins\freshmailintegration\controllers\FreshmailIntegration_EmailController.php on line 27

Is this some kind of namespace issue?

0

Is this some kind of namespace issue?

Yes. If the class you're trying to instantiate is in a namespace, you'd need to indicate that:

$object = $rest = new \the\library\class\namespace\mail_delivery();

If it does not use namespaces, it's probably in the global namespace:

$object = $rest = new \mail_delivery();

If you do it like in your example:

$object = $rest = new mail_delivery();

Then PHP will assuming it's in the current file's namespace (Craft) and you'll get the error that you see.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.